diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index f212402294..3068bd2046 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -181,7 +181,11 @@ void MyAvatar::simulate(float deltaTime) { { PerformanceTimer perfTimer("transform"); updateOrientation(deltaTime); - updatePosition(deltaTime); + if (_enablePhysics) { + updatePhysicsPosition(deltaTime); + } else { + updatePosition(deltaTime); + } } { @@ -1391,6 +1395,26 @@ void MyAvatar::updatePosition(float deltaTime) { measureMotionDerivatives(deltaTime); } + +void MyAvatar::updatePhysicsPosition(float deltaTime) { + glm::vec3 velocity = _velocity; + + bool pushingUp = (_driveKeys[UP] - _driveKeys[DOWN] > 0.0f) || _scriptedMotorVelocity.y > 0.0f; + + glm::quat rotation = getHead()->getCameraOrientation(); + glm::vec3 localVelocity = glm::inverse(rotation) * velocity; + + bool hasFloor = false; + glm::vec3 newLocalVelocity = applyKeyboardMotor(deltaTime, localVelocity, hasFloor); + newLocalVelocity = applyScriptedMotor(deltaTime, newLocalVelocity); + + // rotate back into world-frame + velocity = rotation * newLocalVelocity; + +} + + + void MyAvatar::updateCollisionWithEnvironment(float deltaTime, float radius) { glm::vec3 up = getBodyUpDirection(); const float ENVIRONMENT_SURFACE_ELASTICITY = 0.0f; diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index f2f965032d..d74b7fc5ac 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -235,6 +235,7 @@ private: glm::vec3 applyKeyboardMotor(float deltaTime, const glm::vec3& velocity, bool walkingOnFloor); glm::vec3 applyScriptedMotor(float deltaTime, const glm::vec3& velocity); void updatePosition(float deltaTime); + void updatePhysicsPosition(float deltaTime); void updateCollisionWithAvatars(float deltaTime); void updateCollisionWithEnvironment(float deltaTime, float radius); void updateCollisionWithVoxels(float deltaTime, float radius); diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index 2cfa50b44d..63e6901ec4 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -370,7 +370,7 @@ void PhysicsEngine::computeCollisionEvents() { btBroadphasePairArray& pairArray = _avatarGhostObject->getOverlappingPairCache()->getOverlappingPairArray(); int numPairs = pairArray.size(); - for (int i=0;i