From 78c2e06b5848b97f9ddeaf97d2a374c6a12a5c03 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 14 Jan 2018 18:05:29 +0100 Subject: [PATCH] Sdk/PhysicsSystem3D: Fix CollisionComponent3D teleportating causing velocity increase in physical objects --- SDK/src/NDK/Systems/PhysicsSystem3D.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/SDK/src/NDK/Systems/PhysicsSystem3D.cpp b/SDK/src/NDK/Systems/PhysicsSystem3D.cpp index 5d5a1883d..d30a2f12a 100644 --- a/SDK/src/NDK/Systems/PhysicsSystem3D.cpp +++ b/SDK/src/NDK/Systems/PhysicsSystem3D.cpp @@ -60,6 +60,18 @@ namespace Ndk { m_dynamicObjects.Remove(entity); m_staticObjects.Insert(entity); + + // If entities just got added to the system, teleport them to their NodeComponent position/rotation + // This will prevent the physics engine to mess with the scene while correcting position/rotation + if (justAdded) + { + auto& collision = entity->GetComponent(); + auto& node = entity->GetComponent(); + + Nz::RigidBody3D* physObj = collision.GetStaticBody(); + physObj->SetPosition(node.GetPosition()); + physObj->SetRotation(node.GetRotation()); + } } if (!m_world)