From 4d52caccde7e6dc7833c23ecf9498eae21fe40da Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Thu, 22 Mar 2018 17:39:22 -0700 Subject: [PATCH] making some more requested changes --- interface/src/avatar/MyAvatar.cpp | 28 ++++++++------------------ interface/src/avatar/MyAvatar.h | 1 + libraries/shared/src/AvatarConstants.h | 2 ++ 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 81109e722e..5f6f32b4f0 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -71,7 +71,6 @@ const float YAW_SPEED_DEFAULT = 100.0f; // degrees/sec const float PITCH_SPEED_DEFAULT = 75.0f; // degrees/sec const float MAX_BOOST_SPEED = 0.5f * DEFAULT_AVATAR_MAX_WALKING_SPEED; // action motor gets additive boost below this speed -const float AVATAR_RUN_SPEED = DEFAULT_AVATAR_MAX_WALKING_SPEED * 3.0f; const float MIN_AVATAR_SPEED = 0.05f; const float MIN_AVATAR_SPEED_SQUARED = MIN_AVATAR_SPEED * MIN_AVATAR_SPEED; // speed is set to zero below this @@ -2187,11 +2186,7 @@ void MyAvatar::updateActionMotor(float deltaTime) { glm::vec3 direction = forward + right; if (state == CharacterController::State::Hover || _characterController.computeCollisionGroup() == BULLET_COLLISION_GROUP_COLLISIONLESS) { - // we can fly --> support vertical motion - const float SPRINT_IMPULSE = 4.0f; - const float WALK_IMPULSE = 1.0f; - float impulse = _sprint ? SPRINT_IMPULSE : WALK_IMPULSE; - glm::vec3 up = (getDriveKey(TRANSLATE_Y) * impulse) * IDENTITY_UP; + glm::vec3 up = (getDriveKey(TRANSLATE_Y)) * IDENTITY_UP; direction += up; } @@ -2208,12 +2203,11 @@ void MyAvatar::updateActionMotor(float deltaTime) { if (state == CharacterController::State::Hover) { // we're flying --> complex acceleration curve that builds on top of current motor speed and caps at some max speed - const float WALK_SPEED_FACTOR = 1.8f; - const float SPRINT_SPEED_FACTOR = 5.0f; + float motorSpeed = glm::length(_actionMotorVelocity); - float finalMaxMotorSpeed = getSensorToWorldScale() * DEFAULT_AVATAR_MAX_FLYING_SPEED; + float finalMaxMotorSpeed = getSensorToWorldScale() * DEFAULT_AVATAR_MAX_FLYING_SPEED * _walkSpeedScalar; float speedGrowthTimescale = 2.0f; - float speedIncreaseFactor = _sprint ? SPRINT_SPEED_FACTOR : WALK_SPEED_FACTOR; + float speedIncreaseFactor = 1.8f * _walkSpeedScalar; motorSpeed *= 1.0f + glm::clamp(deltaTime / speedGrowthTimescale, 0.0f, 1.0f) * speedIncreaseFactor; const float maxBoostSpeed = getSensorToWorldScale() * MAX_BOOST_SPEED; @@ -2229,7 +2223,7 @@ void MyAvatar::updateActionMotor(float deltaTime) { _actionMotorVelocity = motorSpeed * direction; } else { // we're interacting with a floor --> simple horizontal speed and exponential decay - _actionMotorVelocity = getSensorToWorldScale() * _walkSpeed.get() * direction; + _actionMotorVelocity = getSensorToWorldScale() * (_walkSpeed.get() * _walkSpeedScalar) * direction; } float boomChange = getDriveKey(ZOOM); @@ -2522,7 +2516,7 @@ bool MyAvatar::safeLanding(const glm::vec3& position) { // If position is not reliably safe from being stuck by physics, answer true and place a candidate better position in betterPositionOut. bool MyAvatar::requiresSafeLanding(const glm::vec3& positionIn, glm::vec3& betterPositionOut) { - // We begin with utilities and tests. The Algorithm in four parts is below. + // We begin with utilities and tests. The Algorithm infour parts is below. auto halfHeight = _characterController.getCapsuleHalfHeight() + _characterController.getCapsuleRadius(); if (halfHeight == 0) { return false; // zero height avatar @@ -2822,17 +2816,11 @@ float MyAvatar::getUserEyeHeight() const { } float MyAvatar::getWalkSpeed() const { - return _walkSpeed.get(); + return _walkSpeed.get() * _walkSpeedScalar; } void MyAvatar::setSprintMode(bool sprint) { - _sprint = sprint; - - if (_sprint) { - _walkSpeed.set(AVATAR_RUN_SPEED); - } else { - _walkSpeed.set(DEFAULT_AVATAR_MAX_WALKING_SPEED); - } + _walkSpeedScalar = sprint ? AVATAR_SPRINT_SPEED_SCALAR : AVATAR_WALK_SPEED_SCALAR; } void MyAvatar::setWalkSpeed(float value) { diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 813aa7a9a7..4830004375 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -868,6 +868,7 @@ private: // max unscaled forward movement speed ThreadSafeValueCache _walkSpeed { DEFAULT_AVATAR_MAX_WALKING_SPEED }; + float _walkSpeedScalar { AVATAR_WALK_SPEED_SCALAR }; }; QScriptValue audioListenModeToScriptValue(QScriptEngine* engine, const AudioListenerMode& audioListenerMode); diff --git a/libraries/shared/src/AvatarConstants.h b/libraries/shared/src/AvatarConstants.h index 4942c63e27..930da6a494 100644 --- a/libraries/shared/src/AvatarConstants.h +++ b/libraries/shared/src/AvatarConstants.h @@ -59,5 +59,7 @@ static const float MIN_AVATAR_SCALE = 0.005f; static const float MAX_AVATAR_HEIGHT = 1000.0f * DEFAULT_AVATAR_HEIGHT; // meters static const float MIN_AVATAR_HEIGHT = 0.005f * DEFAULT_AVATAR_HEIGHT; // meters +static const float AVATAR_WALK_SPEED_SCALAR = 1.0f; +static const float AVATAR_SPRINT_SPEED_SCALAR = 3.0f; #endif // hifi_AvatarConstants_h