From b1fcb43246047e113d56ce2fca784a66bba6d191 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 3 May 2018 16:23:13 -0700 Subject: [PATCH] send ownership removal packet when dynamic object leaves bullet --- .../physics/src/PhysicalEntitySimulation.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libraries/physics/src/PhysicalEntitySimulation.cpp b/libraries/physics/src/PhysicalEntitySimulation.cpp index 8e2695fbfd..4f8e8342c8 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.cpp +++ b/libraries/physics/src/PhysicalEntitySimulation.cpp @@ -130,7 +130,21 @@ void PhysicalEntitySimulation::changeEntityInternal(EntityItemPointer entity) { bool canBeKinematic = region <= workload::Region::R3; if (motionState) { if (!shouldBePhysical) { - // the entity should be removed from the physical simulation + if (motionState->isLocallyOwned()) { + // zero velocities by first deactivating the RigidBody + btRigidBody* body = motionState->getRigidBody(); + if (body) { + body->forceActivationState(ISLAND_SLEEPING); + motionState->updateSendVelocities(); // has side-effect of zeroing entity velocities for inactive body + } + + // send packet to remove ownership + // NOTE: this packet will NOT be resent if lost, but the good news is: + // the entity-server will eventually clear velocity and ownership for timeout + motionState->sendUpdate(_entityPacketSender, _physicsEngine->getNumSubsteps()); + } + + // remove from the physical simulation _incomingChanges.remove(motionState); _physicalObjects.remove(motionState); removeOwnershipData(motionState);