fix bug that caused tractor action to go crazy if only one of the two entities it connected were known to interface

This commit is contained in:
Seth Alves 2018-04-14 12:27:58 -07:00
parent 7c65c9c444
commit 22fd4a7116

View file

@ -47,19 +47,22 @@ ObjectActionTractor::~ObjectActionTractor() {
bool ObjectActionTractor::getTarget(float deltaTimeStep, glm::quat& rotation, glm::vec3& position, bool ObjectActionTractor::getTarget(float deltaTimeStep, glm::quat& rotation, glm::vec3& position,
glm::vec3& linearVelocity, glm::vec3& angularVelocity, glm::vec3& linearVelocity, glm::vec3& angularVelocity,
float& linearTimeScale, float& angularTimeScale) { float& linearTimeScale, float& angularTimeScale) {
SpatiallyNestablePointer other = getOther(); bool success { true };
EntityItemPointer other = std::dynamic_pointer_cast<EntityItem>(getOther());
withReadLock([&]{ withReadLock([&]{
linearTimeScale = _linearTimeScale; linearTimeScale = _linearTimeScale;
angularTimeScale = _angularTimeScale; angularTimeScale = _angularTimeScale;
if (!_otherID.isNull()) { if (!_otherID.isNull()) {
if (other) { if (other && other->isReadyToComputeShape()) {
rotation = _desiredRotationalTarget * other->getWorldOrientation(); rotation = _desiredRotationalTarget * other->getWorldOrientation();
position = other->getWorldOrientation() * _desiredPositionalTarget + other->getWorldPosition(); position = other->getWorldOrientation() * _desiredPositionalTarget + other->getWorldPosition();
} else { } 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; linearTimeScale = FLT_MAX;
angularTimeScale = FLT_MAX; angularTimeScale = FLT_MAX;
success = false;
} }
} else { } else {
rotation = _desiredRotationalTarget; rotation = _desiredRotationalTarget;
@ -68,7 +71,7 @@ bool ObjectActionTractor::getTarget(float deltaTimeStep, glm::quat& rotation, gl
linearVelocity = glm::vec3(); linearVelocity = glm::vec3();
angularVelocity = glm::vec3(); angularVelocity = glm::vec3();
}); });
return true; return success;
} }
bool ObjectActionTractor::prepareForTractorUpdate(btScalar deltaTimeStep) { bool ObjectActionTractor::prepareForTractorUpdate(btScalar deltaTimeStep) {
@ -122,6 +125,8 @@ bool ObjectActionTractor::prepareForTractorUpdate(btScalar deltaTimeStep) {
linearTractorCount++; linearTractorCount++;
position += positionForAction; position += positionForAction;
} }
} else {
return false; // we don't have both entities loaded, so don't do anything
} }
} }