From 22fd4a7116cbfa641341004db81983453e379166 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sat, 14 Apr 2018 12:27:58 -0700 Subject: [PATCH] fix bug that caused tractor action to go crazy if only one of the two entities it connected were known to interface --- libraries/physics/src/ObjectActionTractor.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libraries/physics/src/ObjectActionTractor.cpp b/libraries/physics/src/ObjectActionTractor.cpp index bc68d6de73..9b2da22665 100644 --- a/libraries/physics/src/ObjectActionTractor.cpp +++ b/libraries/physics/src/ObjectActionTractor.cpp @@ -47,19 +47,22 @@ ObjectActionTractor::~ObjectActionTractor() { bool ObjectActionTractor::getTarget(float deltaTimeStep, glm::quat& rotation, glm::vec3& position, glm::vec3& linearVelocity, glm::vec3& angularVelocity, float& linearTimeScale, float& angularTimeScale) { - SpatiallyNestablePointer other = getOther(); + bool success { true }; + EntityItemPointer other = std::dynamic_pointer_cast(getOther()); withReadLock([&]{ linearTimeScale = _linearTimeScale; angularTimeScale = _angularTimeScale; if (!_otherID.isNull()) { - if (other) { + if (other && other->isReadyToComputeShape()) { rotation = _desiredRotationalTarget * other->getWorldOrientation(); position = other->getWorldOrientation() * _desiredPositionalTarget + other->getWorldPosition(); } else { - // we should have an "other" but can't find it, so disable the tractor. + // we should have an "other" but can't find it, or its collision shape isn't loaded, + // so disable the tractor. linearTimeScale = FLT_MAX; angularTimeScale = FLT_MAX; + success = false; } } else { rotation = _desiredRotationalTarget; @@ -68,7 +71,7 @@ bool ObjectActionTractor::getTarget(float deltaTimeStep, glm::quat& rotation, gl linearVelocity = glm::vec3(); angularVelocity = glm::vec3(); }); - return true; + return success; } bool ObjectActionTractor::prepareForTractorUpdate(btScalar deltaTimeStep) { @@ -122,6 +125,8 @@ bool ObjectActionTractor::prepareForTractorUpdate(btScalar deltaTimeStep) { linearTractorCount++; position += positionForAction; } + } else { + return false; // we don't have both entities loaded, so don't do anything } }