BsCharacterController.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "BsVector3.h"
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * Controls climbing behaviour for a capsule character controller. Normally the character controller will not
  10. * automatically climb when heights are greater than the assigned step offset. However due to the shape of the capsule
  11. * it might automatically climb over slightly larger heights than assigned step offsets.
  12. */
  13. enum class CharacterClimbingMode
  14. {
  15. Normal, /**< Normal behaviour. Capsule character controller will be able to auto-step over the step offset. */
  16. Constrained /**< The system will attempt to limit auto-step to the provided step offset and no higher. */
  17. };
  18. /** Controls behaviour when a character controller reaches a slope thats larger than its slope offset. */
  19. enum class CharacterNonWalkableMode
  20. {
  21. Prevent, /**< Character will be prevented from going further, but will be allowed to move laterally. */
  22. PreventAndSlide /**< Character will be prevented from going further, but also slide down the slope. */
  23. };
  24. /** Reports in which directions is the character colliding with other objects */
  25. enum class CharacterCollisionFlag
  26. {
  27. Sides = 0x1, /**< Character is colliding with its sides. */
  28. Up = 0x2, /**< Character is colliding with the ceiling. */
  29. Down = 0x4 /**< Character is colliding with the ground. */
  30. };
  31. /** @copydoc CharacterCollisionFlag */
  32. typedef Flags<CharacterCollisionFlag> CharacterCollisionFlags;
  33. BS_FLAGS_OPERATORS(CharacterCollisionFlag)
  34. class BS_CORE_EXPORT CharacterController
  35. {
  36. public:
  37. virtual ~CharacterController() { }
  38. /**
  39. * Moves the controller in the specified direction by the specified amount, while interacting with surrounding
  40. * geometry. Returns flags signaling where collision occurred after the movement.
  41. */
  42. virtual CharacterCollisionFlags move(const Vector3& displacement) = 0;
  43. /** Returns position of the center of the controller. */
  44. virtual Vector3 getPosition() const = 0;
  45. /**
  46. * Sets position of the center of the controller. This will teleport the character to the location. Use move()
  47. * for movement that includes physics.
  48. */
  49. virtual void setPosition(const Vector3& position) = 0;
  50. /** Returns position of the bottom of the controller. Position takes contact offset into account. */
  51. virtual Vector3 getFootPosition() const = 0;
  52. /**
  53. * Sets position of the bottom of the controller. Position takes contact offset into account. This will teleport the
  54. * character to the location. Use move() for movement that includes physics.
  55. */
  56. virtual void setFootPosition(const Vector3& position) = 0;
  57. /** Returns the radius of the controller capsule. */
  58. virtual float getRadius() const = 0;
  59. /** Sets the radius of the controller capsule. */
  60. virtual void setRadius(float radius) = 0;
  61. /** Returns the height of the controller capsule. */
  62. virtual float getHeight() const = 0;
  63. /** Sets the height of the controller capsule. */
  64. virtual void setHeight(float height) = 0;
  65. /** Returns the up direction of capsule. Determines capsule orientation. */
  66. virtual Vector3 getUp() const = 0;
  67. /** Sets the up direction of capsule. Determines capsule orientation. */
  68. virtual void setUp(const Vector3& up) = 0;
  69. /**
  70. * Returns climbing mode that controls what happens when character encounters a height higher than its step offset.
  71. *
  72. * @see CharacterClimbingMode
  73. */
  74. virtual CharacterClimbingMode getClimbingMode() const = 0;
  75. /**
  76. * Sets climbing mode that controls what happens when character encounters a height higher than its step offset.
  77. *
  78. * @see CharacterClimbingMode
  79. */
  80. virtual void setClimbingMode(CharacterClimbingMode mode) = 0;
  81. /**
  82. * Returns non walkable mode that controls what happens when character encounters a slope higher than its slope
  83. * offset.
  84. *
  85. * @see CharacterNonWalkableMode
  86. */
  87. virtual CharacterNonWalkableMode getNonWalkableMode() const = 0;
  88. /**
  89. * Sets non walkable mode that controls what happens when character encounters a slope higher than its slope
  90. * offset.
  91. *
  92. * @see CharacterNonWalkableMode
  93. */
  94. virtual void setNonWalkableMode(CharacterNonWalkableMode mode) = 0;
  95. /**
  96. * Returns minimum distance that the character will move during a call to move(). This is used to stop the recursive
  97. * motion algorithm when the remaining distance is too small.
  98. */
  99. virtual float getMinMoveDistance() = 0;
  100. /**
  101. * Sets minimum distance that the character will move during a call to move(). This is used to stop the recursive
  102. * motion algorithm when the remaining distance is too small.
  103. */
  104. virtual void setMinMoveDistance(float value) = 0;
  105. /**
  106. * Returns the contact offset value. Contact offset specifies a skin around the object within which contacts will
  107. * be generated. It should be a small positive non-zero value.
  108. */
  109. virtual float getContactOffset() = 0;
  110. /**
  111. * Sets the contact offset value. Contact offset specifies a skin around the object within which contacts will
  112. * be generated. It should be a small positive non-zero value.
  113. */
  114. virtual void setContactOffset(float value) = 0;
  115. /**
  116. * Gets the step offset that controls which obstacles will the character be able to automatically step over without
  117. * being stopped. This is the height of the maximum obstacle that will be stepped over (with exceptions, see
  118. * setClimbingMode().
  119. */
  120. virtual float getStepOffset() = 0;
  121. /**
  122. * Sets the step offset that controls which obstacles will the character be able to automatically step over without
  123. * being stopped. This is the height of the maximum obstacle that will be stepped over (with exceptions, see
  124. * setClimbingMode().
  125. */
  126. virtual void setStepOffset(float value) = 0;
  127. /**
  128. * Gets the slope angle that controls which slopes should the character consider too steep and won't be able to
  129. * move over. See setNonWalkableMode() for more information.
  130. */
  131. virtual Radian getSlopeOffset() = 0;
  132. /**
  133. * Sets the slope angle that controls which slopes should the character consider too steep and won't be able to
  134. * move over. See setNonWalkableMode() for more information.
  135. */
  136. virtual void setSlopeOffset(Radian value) = 0;
  137. /** Creates a new character controller. */
  138. static SPtr<CharacterController> create();
  139. };
  140. }