Merge pull request #12894 from sethalves/fix-tractor-action-crazy

fix bug that caused tractor action to go crazy
This commit is contained in:
John Conklin II 2018-04-18 14:13:56 -07:00 committed by GitHub
commit 87f60e1e25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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<EntityItem>(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
}
}