Fix changing Rigid Body center of mass offset

#2325 #3247
This commit is contained in:
Wojtek Figat
2025-10-08 22:16:46 +02:00
parent e2fc8a6283
commit 65cf59642c
3 changed files with 5 additions and 6 deletions

View File

@@ -159,9 +159,10 @@ void RigidBody::SetCenterOfMassOffset(const Float3& value)
{
if (value == _centerOfMassOffset)
return;
Float3 delta = value - _centerOfMassOffset;
_centerOfMassOffset = value;
if (_actor)
PhysicsBackend::SetRigidDynamicActorCenterOfMassOffset(_actor, _centerOfMassOffset);
PhysicsBackend::AddRigidDynamicActorCenterOfMassOffset(_actor, delta);
}
void RigidBody::SetConstraints(const RigidbodyConstraints value)
@@ -356,9 +357,7 @@ void RigidBody::OnDebugDrawSelected()
{
const auto collider = Cast<Collider>(child);
if (collider && collider->GetAttachedRigidBody() == this)
{
collider->OnDebugDrawSelf();
}
}
Actor::OnDebugDrawSelected();
@@ -534,7 +533,7 @@ void RigidBody::BeginPlay(SceneBeginData* data)
// Apply the Center Of Mass offset
if (!_centerOfMassOffset.IsZero())
PhysicsBackend::SetRigidDynamicActorCenterOfMassOffset(_actor, _centerOfMassOffset);
PhysicsBackend::AddRigidDynamicActorCenterOfMassOffset(_actor, _centerOfMassOffset);
// Register actor
PhysicsBackend::AddSceneActor(scene, _actor);