Fix changing CharacterController center at runtime to maintain actor placement
This commit is contained in:
@@ -292,6 +292,21 @@ RigidBody* CharacterController::GetAttachedRigidBody() const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CharacterController::SetCenter(const Vector3& value)
|
||||
{
|
||||
if (value == _center)
|
||||
return;
|
||||
Vector3 delta = value - _center;
|
||||
_center = value;
|
||||
if (_controller)
|
||||
{
|
||||
// Change physics position while maintaining actor placement
|
||||
Vector3 position = PhysicsBackend::GetControllerPosition(_controller);
|
||||
position += _upDirection * delta;
|
||||
PhysicsBackend::SetControllerPosition(_controller, position);
|
||||
}
|
||||
}
|
||||
|
||||
void CharacterController::OnActiveTransformChanged()
|
||||
{
|
||||
if (!_shape)
|
||||
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
/// <summary>
|
||||
/// Sets the center of the collider, measured in the object's local space.
|
||||
/// </summary>
|
||||
API_PROPERTY() void SetCenter(const Vector3& value);
|
||||
API_PROPERTY() virtual void SetCenter(const Vector3& value);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the contact offset. Colliders whose distance is less than the sum of their ContactOffset values will generate contacts. The contact offset must be positive. Contact offset allows the collision detection system to predictively enforce the contact constraint even when the objects are slightly separated.
|
||||
|
||||
Reference in New Issue
Block a user