Fixed fatal bug where rigidbody masses was incorrectly computed when editor is enabled #259

Merged
direnbharwani merged 2 commits from SP3-2-Physics into main 2022-11-23 13:50:22 +08:00
3 changed files with 11 additions and 4 deletions
Showing only changes of commit 1402139369 - Show all commits

View File

@ -250,9 +250,7 @@ namespace SHADE
} }
// A static rigid body is implicitly created on creation of a physics object. // A static rigid body is implicitly created on creation of a physics object.
// We only need to sync rigid bodies here in the event it is non-static. // Nothing is needed here.
physicsObject->SyncRigidBody(*componentGroup.rigidBodyComponent);
} }
void SHPhysicsObjectManager::addCollider(const QueueCommand&, SHPhysicsObject* physicsObject, const PhysicsComponentGroup& componentGroup) void SHPhysicsObjectManager::addCollider(const QueueCommand&, SHPhysicsObject* physicsObject, const PhysicsComponentGroup& componentGroup)
@ -269,7 +267,7 @@ namespace SHADE
//for (int i = 0; i < NUM_SHAPES; ++i) //for (int i = 0; i < NUM_SHAPES; ++i)
// physicsObject->AddCollisionShape(i); // physicsObject->AddCollisionShape(i);
//physicsObject->SyncColliders(*componentGroup.colliderComponent); physicsObject->SyncColliders(*componentGroup.colliderComponent);
} }
void SHPhysicsObjectManager::removeRigidBody(const QueueCommand&, SHPhysicsObject* physicsObject, const PhysicsComponentGroup& componentGroup) void SHPhysicsObjectManager::removeRigidBody(const QueueCommand&, SHPhysicsObject* physicsObject, const PhysicsComponentGroup& componentGroup)

View File

@ -411,7 +411,14 @@ namespace SHADE
objectManager.AddRigidBody(EID); objectManager.AddRigidBody(EID);
if (SHComponentManager::HasComponent<SHColliderComponent>(EID)) if (SHComponentManager::HasComponent<SHColliderComponent>(EID))
{
objectManager.AddCollider(EID); objectManager.AddCollider(EID);
auto* COLLIDER = SHComponentManager::GetComponent<SHColliderComponent>(EID);
for (size_t i = 0; i < COLLIDER->GetCollisionShapes().size(); ++i)
objectManager.AddCollisionShape(EID, i);
}
}; };
//////////////////////////////// ////////////////////////////////

View File

@ -255,6 +255,8 @@ namespace SHADE
// Sync transforms & physics components transforms // Sync transforms & physics components transforms
if (transformComponent && transformComponent->HasChanged()) if (transformComponent && transformComponent->HasChanged())
{ {
physicsObject.GetRigidBody()->setIsSleeping(false);
preUpdateSyncTransform preUpdateSyncTransform
( (
physicsObject physicsObject