From 1402139369b9d553b2ddc102816ea9f03c1525d8 Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Wed, 23 Nov 2022 13:30:28 +0800 Subject: [PATCH] Fixed bug where colliders were not properly added with editor enabled --- .../src/Physics/PhysicsObject/SHPhysicsObjectManager.cpp | 6 ++---- SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp | 7 +++++++ .../src/Physics/System/SHPhysicsSystemRoutines.cpp | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/SHADE_Engine/src/Physics/PhysicsObject/SHPhysicsObjectManager.cpp b/SHADE_Engine/src/Physics/PhysicsObject/SHPhysicsObjectManager.cpp index bd68de82..7c111a2d 100644 --- a/SHADE_Engine/src/Physics/PhysicsObject/SHPhysicsObjectManager.cpp +++ b/SHADE_Engine/src/Physics/PhysicsObject/SHPhysicsObjectManager.cpp @@ -250,9 +250,7 @@ namespace SHADE } // 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. - - physicsObject->SyncRigidBody(*componentGroup.rigidBodyComponent); + // Nothing is needed here. } void SHPhysicsObjectManager::addCollider(const QueueCommand&, SHPhysicsObject* physicsObject, const PhysicsComponentGroup& componentGroup) @@ -269,7 +267,7 @@ namespace SHADE //for (int i = 0; i < NUM_SHAPES; ++i) // physicsObject->AddCollisionShape(i); - //physicsObject->SyncColliders(*componentGroup.colliderComponent); + physicsObject->SyncColliders(*componentGroup.colliderComponent); } void SHPhysicsObjectManager::removeRigidBody(const QueueCommand&, SHPhysicsObject* physicsObject, const PhysicsComponentGroup& componentGroup) diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp index 89be2614..2df5c496 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp +++ b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp @@ -411,7 +411,14 @@ namespace SHADE objectManager.AddRigidBody(EID); if (SHComponentManager::HasComponent(EID)) + { objectManager.AddCollider(EID); + + auto* COLLIDER = SHComponentManager::GetComponent(EID); + for (size_t i = 0; i < COLLIDER->GetCollisionShapes().size(); ++i) + objectManager.AddCollisionShape(EID, i); + } + }; //////////////////////////////// diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp b/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp index 24bd2f81..1d070f00 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp +++ b/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp @@ -255,6 +255,8 @@ namespace SHADE // Sync transforms & physics components transforms if (transformComponent && transformComponent->HasChanged()) { + physicsObject.GetRigidBody()->setIsSleeping(false); + preUpdateSyncTransform ( physicsObject