Showing the changes to libraries/physics/src/ObjectActionSpring.cpp (1 of 1 file). Show all
Unified · Split
| @@ -66,10 +66,15 @@ void ObjectActionSpring::updateActionWorker(btScalar deltaTimeStep) { · 65 unmodified lines | |||
| 66 | if (_linearTimeScale < MAX_TIMESCALE) { | 66 | if (_linearTimeScale < MAX_TIMESCALE) { |
| 67 | btVector3 offset = rigidBody->getCenterOfMassPosition() - glmToBullet(_positionalTarget); | 67 | btVector3 offset = rigidBody->getCenterOfMassPosition() - glmToBullet(_positionalTarget); |
| 68 | float offsetLength = offset.length(); | 68 | float offsetLength = offset.length(); |
| 69 | float speed = (offsetLength > FLT_EPSILON) ? glm::min(offsetLength / _linearTimeScale, SPRING_MAX_SPEED) : 0.0f; | 69 | btVector3 targetVelocity(0.0f, 0.0f, 0.0f); |
| 70 | |||
| 71 | if (offsetLength > 0) { | ||
| 72 | float speed = (offsetLength > FLT_EPSILON) ? glm::min(offsetLength / _linearTimeScale, SPRING_MAX_SPEED) : 0.0f; | ||
| 73 | targetVelocity = (-speed / offsetLength) * offset; | ||
| 74 | } | ||
| 70 | 75 | ||
| 71 | // this action is aggresively critically damped and defeats the current velocity | 76 | // this action is aggresively critically damped and defeats the current velocity |
| 72 | rigidBody->setLinearVelocity((- speed / offsetLength) * offset); | 77 | rigidBody->setLinearVelocity(targetVelocity); |
| 73 | } | 78 | } |
| 74 | 79 | ||
| 75 | if (_angularTimeScale < MAX_TIMESCALE) { | 80 | if (_angularTimeScale < MAX_TIMESCALE) { |