History

fix hold action with zero offsetLength

Brad Hefta-Gaub committed 11 years ago

Commit 21afafd1 parent 7d2bdb31 file · +7 −2Browse files

Showing the changes to libraries/physics/src/ObjectActionSpring.cpp (1 of 1 file). Show all

Unified · Split

libraries/physics/src/ObjectActionSpring.cpp+7−2
@@ -66,10 +66,15 @@ void ObjectActionSpring::updateActionWorker(btScalar deltaTimeStep) { · 65 unmodified lines
6666 if (_linearTimeScale < MAX_TIMESCALE) {
6767 btVector3 offset = rigidBody->getCenterOfMassPosition() - glmToBullet(_positionalTarget);
6868 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+ }
7075
7176 // this action is aggresively critically damped and defeats the current velocity
72− rigidBody->setLinearVelocity((- speed / offsetLength) * offset);
77+ rigidBody->setLinearVelocity(targetVelocity);
7378 }
7479
7580 if (_angularTimeScale < MAX_TIMESCALE) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t