Fixed Rigidbodies not sleeping #251

Merged
direnbharwani merged 2 commits from SP3-2-Physics into main 2022-11-22 20:58:11 +08:00
2 changed files with 12 additions and 5 deletions

View File

@ -47,14 +47,14 @@ namespace SHADE
{ {
// Get the current scene graph to traverse and update // Get the current scene graph to traverse and update
const auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph(); const auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph();
UpdateEntity(SCENE_GRAPH.GetRoot(), !IsRunInEditorPause); UpdateEntity(SCENE_GRAPH.GetRoot(), false);
} }
void SHTransformSystem::TransformPostPhysicsUpdate::Execute(double) noexcept void SHTransformSystem::TransformPostPhysicsUpdate::Execute(double) noexcept
{ {
// Get the current scene graph to traverse and update // Get the current scene graph to traverse and update
const auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph(); const auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph();
UpdateEntity(SCENE_GRAPH.GetRoot(), IsRunInEditorPause); UpdateEntity(SCENE_GRAPH.GetRoot(), true);
} }
void SHTransformSystem::Init() void SHTransformSystem::Init()

View File

@ -302,11 +302,14 @@ namespace SHADE
{ {
colliderComponent->position = WORLD_POS; colliderComponent->position = WORLD_POS;
colliderComponent->orientation = WORLD_ROT; colliderComponent->orientation = WORLD_ROT;
colliderComponent->scale = WORLD_SCL;
if (colliderComponent->scale != WORLD_SCL)
{
colliderComponent->scale = WORLD_SCL;
colliderComponent->RecomputeCollisionShapes(); colliderComponent->RecomputeCollisionShapes();
} }
} }
}
void SHPhysicsSystem::PhysicsPostUpdate::postUpdateSyncTransforms void SHPhysicsSystem::PhysicsPostUpdate::postUpdateSyncTransforms
( (
@ -325,7 +328,11 @@ namespace SHADE
if (physicsObject.GetRigidBody()->isActive()) if (physicsObject.GetRigidBody()->isActive())
physicsObject.prevTransform = CURRENT_TF; physicsObject.prevTransform = CURRENT_TF;
// Sync with rigid bodies. If an object doesn't have a rigidbody, no update is needed here as it is done in pre-update. // Skip sleeping objects
if (physicsObject.GetRigidBody()->isSleeping())
return;
// Sync with rigid bodies
if (rigidBodyComponent && SHSceneManager::CheckNodeAndComponentsActive<SHRigidBodyComponent>(physicsObject.entityID)) if (rigidBodyComponent && SHSceneManager::CheckNodeAndComponentsActive<SHRigidBodyComponent>(physicsObject.entityID))
{ {
// Skip static bodies // Skip static bodies