From 78e59106b40b63c833c7f533ff4fe7bb078d729e Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 3 Aug 2016 15:21:49 -0700 Subject: [PATCH 1/3] adjust threshold for how far above the ground will cause the avatar to auto-fly --- libraries/physics/src/CharacterController.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libraries/physics/src/CharacterController.cpp b/libraries/physics/src/CharacterController.cpp index 30fb3536ca..df166ceb59 100644 --- a/libraries/physics/src/CharacterController.cpp +++ b/libraries/physics/src/CharacterController.cpp @@ -540,7 +540,8 @@ void CharacterController::preSimulation() { btScalar rayLength = _radius + MAX_FALL_HEIGHT; btVector3 rayEnd = rayStart - rayLength * _currentUp; - const btScalar JUMP_PROXIMITY_THRESHOLD = 0.1f * _radius; + const btScalar FLY_TO_GROUND_THRESHOLD = 0.1f * _radius; + const btScalar GROUND_TO_AUTOFLY_THRESHOLD = 0.5f * _radius; const quint64 TAKE_OFF_TO_IN_AIR_PERIOD = 250 * MSECS_PER_SECOND; const btScalar MIN_HOVER_HEIGHT = 2.5f; const quint64 JUMP_TO_HOVER_PERIOD = 1100 * MSECS_PER_SECOND; @@ -581,7 +582,7 @@ void CharacterController::preSimulation() { _takeoffJumpButtonID = _jumpButtonDownCount; _takeoffToInAirStartTime = now; SET_STATE(State::Takeoff, "jump pressed"); - } else if (rayHasHit && !_hasSupport && _floorDistance > JUMP_PROXIMITY_THRESHOLD) { + } else if (rayHasHit && !_hasSupport && _floorDistance > GROUND_TO_AUTOFLY_THRESHOLD) { SET_STATE(State::InAir, "falling"); } break; @@ -595,7 +596,7 @@ void CharacterController::preSimulation() { } break; case State::InAir: { - if ((velocity.dot(_currentUp) <= (JUMP_SPEED / 2.0f)) && ((_floorDistance < JUMP_PROXIMITY_THRESHOLD) || _hasSupport)) { + if ((velocity.dot(_currentUp) <= (JUMP_SPEED / 2.0f)) && ((_floorDistance < FLY_TO_GROUND_THRESHOLD) || _hasSupport)) { SET_STATE(State::Ground, "hit ground"); } else { btVector3 desiredVelocity = _targetVelocity; @@ -614,7 +615,7 @@ void CharacterController::preSimulation() { case State::Hover: if ((_floorDistance < MIN_HOVER_HEIGHT) && !jumpButtonHeld && !flyingFast) { SET_STATE(State::InAir, "near ground"); - } else if (((_floorDistance < JUMP_PROXIMITY_THRESHOLD) || _hasSupport) && !flyingFast) { + } else if (((_floorDistance < FLY_TO_GROUND_THRESHOLD) || _hasSupport) && !flyingFast) { SET_STATE(State::Ground, "touching ground"); } break; From e1c7ced652720642ed032a966fa38400828245cb Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 4 Aug 2016 09:54:26 -0700 Subject: [PATCH 2/3] increase GROUND_TO_AUTOFLY_THRESHOLD --- libraries/physics/src/CharacterController.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/physics/src/CharacterController.cpp b/libraries/physics/src/CharacterController.cpp index df166ceb59..1c6836769b 100644 --- a/libraries/physics/src/CharacterController.cpp +++ b/libraries/physics/src/CharacterController.cpp @@ -541,7 +541,7 @@ void CharacterController::preSimulation() { btVector3 rayEnd = rayStart - rayLength * _currentUp; const btScalar FLY_TO_GROUND_THRESHOLD = 0.1f * _radius; - const btScalar GROUND_TO_AUTOFLY_THRESHOLD = 0.5f * _radius; + const btScalar GROUND_TO_AUTOFLY_THRESHOLD = 1.2f * _radius; const quint64 TAKE_OFF_TO_IN_AIR_PERIOD = 250 * MSECS_PER_SECOND; const btScalar MIN_HOVER_HEIGHT = 2.5f; const quint64 JUMP_TO_HOVER_PERIOD = 1100 * MSECS_PER_SECOND; From aeadbda1e171cfe67f19af7dcf687c02812b5171 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 4 Aug 2016 11:34:42 -0700 Subject: [PATCH 3/3] adjust ground-to-fly logic --- libraries/physics/src/CharacterController.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/physics/src/CharacterController.cpp b/libraries/physics/src/CharacterController.cpp index 1c6836769b..b5ef03be0f 100644 --- a/libraries/physics/src/CharacterController.cpp +++ b/libraries/physics/src/CharacterController.cpp @@ -534,14 +534,14 @@ void CharacterController::preSimulation() { // scan for distant floor // rayStart is at center of bottom sphere - btVector3 rayStart = _characterBodyTransform.getOrigin() - _halfHeight * _currentUp; + btVector3 rayStart = _characterBodyTransform.getOrigin(); // rayEnd is straight down MAX_FALL_HEIGHT btScalar rayLength = _radius + MAX_FALL_HEIGHT; btVector3 rayEnd = rayStart - rayLength * _currentUp; const btScalar FLY_TO_GROUND_THRESHOLD = 0.1f * _radius; - const btScalar GROUND_TO_AUTOFLY_THRESHOLD = 1.2f * _radius; + const btScalar GROUND_TO_FLY_THRESHOLD = 0.8f * _radius + _halfHeight; const quint64 TAKE_OFF_TO_IN_AIR_PERIOD = 250 * MSECS_PER_SECOND; const btScalar MIN_HOVER_HEIGHT = 2.5f; const quint64 JUMP_TO_HOVER_PERIOD = 1100 * MSECS_PER_SECOND; @@ -554,7 +554,7 @@ void CharacterController::preSimulation() { bool rayHasHit = rayCallback.hasHit(); if (rayHasHit) { _rayHitStartTime = now; - _floorDistance = rayLength * rayCallback.m_closestHitFraction - _radius; + _floorDistance = rayLength * rayCallback.m_closestHitFraction - (_radius + _halfHeight); } else if ((now - _rayHitStartTime) < RAY_HIT_START_PERIOD) { rayHasHit = true; } else { @@ -582,7 +582,7 @@ void CharacterController::preSimulation() { _takeoffJumpButtonID = _jumpButtonDownCount; _takeoffToInAirStartTime = now; SET_STATE(State::Takeoff, "jump pressed"); - } else if (rayHasHit && !_hasSupport && _floorDistance > GROUND_TO_AUTOFLY_THRESHOLD) { + } else if (rayHasHit && !_hasSupport && _floorDistance > GROUND_TO_FLY_THRESHOLD) { SET_STATE(State::InAir, "falling"); } break;