Browse Source

Fixed vertical velocity being set to NaN when any component of the gravity vector is positive

louis-mclaughlin 11 years ago
parent
commit
f7840a09ee
1 changed files with 4 additions and 4 deletions
  1. 4 4
      gameplay/src/PhysicsCharacter.cpp

+ 4 - 4
gameplay/src/PhysicsCharacter.cpp

@@ -255,11 +255,11 @@ void PhysicsCharacter::jump(float height, bool force)
     //  a == acceleration (inverse gravity)
     //  a == acceleration (inverse gravity)
     //  s == linear displacement (height)
     //  s == linear displacement (height)
     GP_ASSERT(Game::getInstance()->getPhysicsController());
     GP_ASSERT(Game::getInstance()->getPhysicsController());
-    Vector3 jumpVelocity = -Game::getInstance()->getPhysicsController()->getGravity() * height * 2.0f;
+    Vector3 jumpVelocity = Game::getInstance()->getPhysicsController()->getGravity() * height * 2.0f;
     jumpVelocity.set(
     jumpVelocity.set(
-        jumpVelocity.x == 0 ? 0 : std::sqrt(jumpVelocity.x),
-        jumpVelocity.y == 0 ? 0 : std::sqrt(jumpVelocity.y),
-        jumpVelocity.z == 0 ? 0 : std::sqrt(jumpVelocity.z));
+        jumpVelocity.x == 0 ? 0 : std::sqrt(std::fabs(jumpVelocity.x)) * (jumpVelocity.x > 0 ? 1.0f : -1.0f),
+        jumpVelocity.y == 0 ? 0 : std::sqrt(std::fabs(jumpVelocity.y)) * (jumpVelocity.y < 0 ? 1.0f : -1.0f),
+        jumpVelocity.z == 0 ? 0 : std::sqrt(std::fabs(jumpVelocity.z)) * (jumpVelocity.z > 0 ? 1.0f : -1.0f));
     _verticalVelocity += BV(jumpVelocity);
     _verticalVelocity += BV(jumpVelocity);
 }
 }