diff --git a/ChangeLog.md b/ChangeLog.md index f78bd943f..5b19b89c4 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -64,6 +64,7 @@ Nazara Development Kit: - Fix GraphicsComponent cloning not copying renderable local matrices - ⚠️ Rename PhysicsComponent3D::[Get|Set]Velocity to [Get|Set]LinearVelocity - Add OnEntityDisabled and OnEntityEnabled callbacks to BaseComponent +- Disabling an entity with a CollisionComponent3D or PhysicsComponent3D will properly disable it from the physics simulation # 0.4: diff --git a/SDK/include/NDK/Components/CollisionComponent3D.hpp b/SDK/include/NDK/Components/CollisionComponent3D.hpp index ce1b719ca..f57464a79 100644 --- a/SDK/include/NDK/Components/CollisionComponent3D.hpp +++ b/SDK/include/NDK/Components/CollisionComponent3D.hpp @@ -40,6 +40,8 @@ namespace Ndk void OnComponentAttached(BaseComponent& component) override; void OnComponentDetached(BaseComponent& component) override; void OnDetached() override; + void OnEntityDisabled() override; + void OnEntityEnabled() override; std::unique_ptr m_staticBody; Nz::Collider3DRef m_geom; diff --git a/SDK/include/NDK/Components/PhysicsComponent3D.hpp b/SDK/include/NDK/Components/PhysicsComponent3D.hpp index b989f17ee..292c5f9ab 100644 --- a/SDK/include/NDK/Components/PhysicsComponent3D.hpp +++ b/SDK/include/NDK/Components/PhysicsComponent3D.hpp @@ -65,6 +65,8 @@ namespace Ndk void OnComponentDetached(BaseComponent& component) override; void OnDetached() override; void OnEntityDestruction() override; + void OnEntityDisabled() override; + void OnEntityEnabled() override; std::unique_ptr m_object; }; diff --git a/SDK/src/NDK/Components/CollisionComponent3D.cpp b/SDK/src/NDK/Components/CollisionComponent3D.cpp index a853cbb55..7fab3d9be 100644 --- a/SDK/src/NDK/Components/CollisionComponent3D.cpp +++ b/SDK/src/NDK/Components/CollisionComponent3D.cpp @@ -57,7 +57,7 @@ namespace Ndk NazaraAssert(entityWorld->HasSystem(), "World must have a physics system"); Nz::PhysWorld3D& physWorld = entityWorld->GetSystem().GetWorld(); - m_staticBody.reset(new Nz::RigidBody3D(&physWorld, m_geom)); + m_staticBody = std::make_unique(&physWorld, m_geom); m_staticBody->EnableAutoSleep(false); } @@ -104,5 +104,17 @@ namespace Ndk m_staticBody.reset(); } + void CollisionComponent3D::OnEntityDisabled() + { + if (m_staticBody) + m_staticBody->EnableSimulation(false); + } + + void CollisionComponent3D::OnEntityEnabled() + { + if (m_staticBody) + m_staticBody->EnableSimulation(true); + } + ComponentIndex CollisionComponent3D::componentIndex; } diff --git a/SDK/src/NDK/Components/PhysicsComponent3D.cpp b/SDK/src/NDK/Components/PhysicsComponent3D.cpp index 09b323d2c..be7ea9f86 100644 --- a/SDK/src/NDK/Components/PhysicsComponent3D.cpp +++ b/SDK/src/NDK/Components/PhysicsComponent3D.cpp @@ -93,5 +93,19 @@ namespace Ndk m_object.reset(); } + void PhysicsComponent3D::OnEntityDisabled() + { + NazaraAssert(m_object, "Invalid physics object"); + + m_object->EnableSimulation(false); + } + + void PhysicsComponent3D::OnEntityEnabled() + { + NazaraAssert(m_object, "Invalid physics object"); + + m_object->EnableSimulation(true); + } + ComponentIndex PhysicsComponent3D::componentIndex; }