send ownership removal packet when dynamic object leaves bullet

This commit is contained in:
Andrew Meadows 2018-05-03 16:23:13 -07:00
parent 3d16c9014f
commit b1fcb43246

View file

@ -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);