Add AutoGravity option to CharacterController for logic from 4de9e9d918
This commit is contained in:
@@ -131,6 +131,11 @@ void CharacterController::SetMinMoveDistance(float value)
|
||||
_minMoveDistance = Math::Max(value, 0.0f);
|
||||
}
|
||||
|
||||
void CharacterController::SetAutoGravity(bool value)
|
||||
{
|
||||
_autoGravity = value;
|
||||
}
|
||||
|
||||
Vector3 CharacterController::GetVelocity() const
|
||||
{
|
||||
return _controller ? PhysicsBackend::GetRigidDynamicActorLinearVelocity(PhysicsBackend::GetControllerRigidDynamicActor(_controller)) : Vector3::Zero;
|
||||
@@ -262,10 +267,12 @@ void CharacterController::UpdateBounds()
|
||||
void CharacterController::AddMovement(const Vector3& translation, const Quaternion& rotation)
|
||||
{
|
||||
Vector3 displacement = translation;
|
||||
|
||||
// Apply gravity
|
||||
const float deltaTime = Time::GetCurrentSafe()->DeltaTime.GetTotalSeconds();
|
||||
displacement += GetPhysicsScene()->GetGravity() * deltaTime;
|
||||
if (_autoGravity)
|
||||
{
|
||||
// Apply gravity
|
||||
const float deltaTime = Time::GetCurrentSafe()->DeltaTime.GetTotalSeconds();
|
||||
displacement += GetPhysicsScene()->GetGravity() * deltaTime;
|
||||
}
|
||||
|
||||
Move(displacement);
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ private:
|
||||
float _height;
|
||||
float _minMoveDistance;
|
||||
bool _isUpdatingTransform;
|
||||
bool _autoGravity = false;
|
||||
Vector3 _upDirection;
|
||||
Vector3 _gravityDisplacement;
|
||||
NonWalkableModes _nonWalkableMode;
|
||||
@@ -148,6 +149,20 @@ public:
|
||||
/// </summary>
|
||||
API_PROPERTY() void SetMinMoveDistance(float value);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the automatic gravity force applying mode. Can be toggled off if gameplay controls character movement velocity including gravity, or toggled on if gravity should be applied together with root motion from animation movement.
|
||||
/// </summary>
|
||||
API_PROPERTY(Attributes="EditorOrder(250), DefaultValue(false), EditorDisplay(\"Character Controller\")")
|
||||
bool GetAutoGravity() const
|
||||
{
|
||||
return _autoGravity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the automatic gravity force applying mode. Can be toggled off if gameplay controls character movement velocity including gravity, or toggled on if gravity should be applied together with root motion from animation movement.
|
||||
/// </summary>
|
||||
API_PROPERTY() void SetAutoGravity(bool value);
|
||||
|
||||
public:
|
||||
/// <summary>
|
||||
/// Gets the linear velocity of the Character Controller. This allows tracking how fast the character is actually moving, for instance when it is stuck at a wall this value will be the near zero vector.
|
||||
|
||||
Reference in New Issue
Block a user