mirror of
https://github.com/lubosz/overte.git
synced 2025-04-27 21:55:28 +02:00
Calculate jump speed based on canonical jump height.
This commit is contained in:
parent
e0ff7f5f40
commit
4f830cf1dc
4 changed files with 24 additions and 12 deletions
|
@ -1507,6 +1507,7 @@ void MyAvatar::prepareForPhysicsSimulation() {
|
||||||
}
|
}
|
||||||
_characterController.handleChangedCollisionGroup();
|
_characterController.handleChangedCollisionGroup();
|
||||||
_characterController.setParentVelocity(parentVelocity);
|
_characterController.setParentVelocity(parentVelocity);
|
||||||
|
_characterController.setScaleFactor(getSensorToWorldScale());
|
||||||
|
|
||||||
_characterController.setPositionAndOrientation(getPosition(), getOrientation());
|
_characterController.setPositionAndOrientation(getPosition(), getOrientation());
|
||||||
auto headPose = getControllerPoseInAvatarFrame(controller::Action::HEAD);
|
auto headPose = getControllerPoseInAvatarFrame(controller::Action::HEAD);
|
||||||
|
|
|
@ -12,14 +12,13 @@
|
||||||
#include "CharacterController.h"
|
#include "CharacterController.h"
|
||||||
|
|
||||||
#include <NumericalConstants.h>
|
#include <NumericalConstants.h>
|
||||||
|
#include <AvatarConstants.h>
|
||||||
|
|
||||||
#include "ObjectMotionState.h"
|
#include "ObjectMotionState.h"
|
||||||
#include "PhysicsHelpers.h"
|
#include "PhysicsHelpers.h"
|
||||||
#include "PhysicsLogging.h"
|
#include "PhysicsLogging.h"
|
||||||
|
|
||||||
const btVector3 LOCAL_UP_AXIS(0.0f, 1.0f, 0.0f);
|
const btVector3 LOCAL_UP_AXIS(0.0f, 1.0f, 0.0f);
|
||||||
const float JUMP_SPEED = 3.5f;
|
|
||||||
const float MAX_FALL_HEIGHT = 20.0f;
|
|
||||||
|
|
||||||
#ifdef DEBUG_STATE_CHANGE
|
#ifdef DEBUG_STATE_CHANGE
|
||||||
#define SET_STATE(desiredState, reason) setState(desiredState, reason)
|
#define SET_STATE(desiredState, reason) setState(desiredState, reason)
|
||||||
|
@ -62,12 +61,11 @@ CharacterController::CharacterMotor::CharacterMotor(const glm::vec3& vel, const
|
||||||
}
|
}
|
||||||
|
|
||||||
CharacterController::CharacterController() {
|
CharacterController::CharacterController() {
|
||||||
_floorDistance = MAX_FALL_HEIGHT;
|
_floorDistance = _scaleFactor * DEFAULT_AVATAR_FALL_HEIGHT;
|
||||||
|
|
||||||
_targetVelocity.setValue(0.0f, 0.0f, 0.0f);
|
_targetVelocity.setValue(0.0f, 0.0f, 0.0f);
|
||||||
_followDesiredBodyTransform.setIdentity();
|
_followDesiredBodyTransform.setIdentity();
|
||||||
_followTimeRemaining = 0.0f;
|
_followTimeRemaining = 0.0f;
|
||||||
_jumpSpeed = JUMP_SPEED;
|
|
||||||
_state = State::Hover;
|
_state = State::Hover;
|
||||||
_isPushingUp = false;
|
_isPushingUp = false;
|
||||||
_rayHitStartTime = 0;
|
_rayHitStartTime = 0;
|
||||||
|
@ -376,8 +374,7 @@ void CharacterController::updateGravity() {
|
||||||
if (_state == State::Hover || collisionGroup == BULLET_COLLISION_GROUP_COLLISIONLESS) {
|
if (_state == State::Hover || collisionGroup == BULLET_COLLISION_GROUP_COLLISIONLESS) {
|
||||||
_gravity = 0.0f;
|
_gravity = 0.0f;
|
||||||
} else {
|
} else {
|
||||||
const float DEFAULT_CHARACTER_GRAVITY = -5.0f;
|
_gravity = DEFAULT_AVATAR_GRAVITY;
|
||||||
_gravity = DEFAULT_CHARACTER_GRAVITY;
|
|
||||||
}
|
}
|
||||||
if (_rigidBody) {
|
if (_rigidBody) {
|
||||||
_rigidBody->setGravity(_gravity * _currentUp);
|
_rigidBody->setGravity(_gravity * _currentUp);
|
||||||
|
@ -653,7 +650,7 @@ void CharacterController::updateState() {
|
||||||
const btScalar FLY_TO_GROUND_THRESHOLD = 0.1f * _radius;
|
const btScalar FLY_TO_GROUND_THRESHOLD = 0.1f * _radius;
|
||||||
const btScalar GROUND_TO_FLY_THRESHOLD = 0.8f * _radius + _halfHeight;
|
const btScalar GROUND_TO_FLY_THRESHOLD = 0.8f * _radius + _halfHeight;
|
||||||
const quint64 TAKE_OFF_TO_IN_AIR_PERIOD = 250 * MSECS_PER_SECOND;
|
const quint64 TAKE_OFF_TO_IN_AIR_PERIOD = 250 * MSECS_PER_SECOND;
|
||||||
const btScalar MIN_HOVER_HEIGHT = 2.5f;
|
const btScalar MIN_HOVER_HEIGHT = _scaleFactor * DEFAULT_AVATAR_MIN_HOVER_HEIGHT;
|
||||||
const quint64 JUMP_TO_HOVER_PERIOD = 1100 * MSECS_PER_SECOND;
|
const quint64 JUMP_TO_HOVER_PERIOD = 1100 * MSECS_PER_SECOND;
|
||||||
|
|
||||||
// scan for distant floor
|
// scan for distant floor
|
||||||
|
@ -663,7 +660,7 @@ void CharacterController::updateState() {
|
||||||
btScalar rayLength = _radius;
|
btScalar rayLength = _radius;
|
||||||
int16_t collisionGroup = computeCollisionGroup();
|
int16_t collisionGroup = computeCollisionGroup();
|
||||||
if (collisionGroup == BULLET_COLLISION_GROUP_MY_AVATAR) {
|
if (collisionGroup == BULLET_COLLISION_GROUP_MY_AVATAR) {
|
||||||
rayLength += MAX_FALL_HEIGHT;
|
rayLength += _scaleFactor * DEFAULT_AVATAR_FALL_HEIGHT;
|
||||||
} else {
|
} else {
|
||||||
rayLength += MIN_HOVER_HEIGHT;
|
rayLength += MIN_HOVER_HEIGHT;
|
||||||
}
|
}
|
||||||
|
@ -717,11 +714,15 @@ void CharacterController::updateState() {
|
||||||
SET_STATE(State::Hover, "no ground");
|
SET_STATE(State::Hover, "no ground");
|
||||||
} else if ((now - _takeoffToInAirStartTime) > TAKE_OFF_TO_IN_AIR_PERIOD) {
|
} else if ((now - _takeoffToInAirStartTime) > TAKE_OFF_TO_IN_AIR_PERIOD) {
|
||||||
SET_STATE(State::InAir, "takeoff done");
|
SET_STATE(State::InAir, "takeoff done");
|
||||||
velocity += _jumpSpeed * _currentUp;
|
|
||||||
|
// compute jumpSpeed based on the scaled jump height for the default avatar in default gravity.
|
||||||
|
float jumpSpeed = sqrtf(2.0f * DEFAULT_AVATAR_GRAVITY * _scaleFactor * DEFAULT_AVATAR_JUMP_HEIGHT);
|
||||||
|
velocity += jumpSpeed * _currentUp;
|
||||||
_rigidBody->setLinearVelocity(velocity);
|
_rigidBody->setLinearVelocity(velocity);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case State::InAir: {
|
case State::InAir: {
|
||||||
|
const float JUMP_SPEED = _scaleFactor * DEFAULT_AVATAR_JUMP_SPEED;
|
||||||
if ((velocity.dot(_currentUp) <= (JUMP_SPEED / 2.0f)) && ((_floorDistance < FLY_TO_GROUND_THRESHOLD) || _hasSupport)) {
|
if ((velocity.dot(_currentUp) <= (JUMP_SPEED / 2.0f)) && ((_floorDistance < FLY_TO_GROUND_THRESHOLD) || _hasSupport)) {
|
||||||
SET_STATE(State::Ground, "hit ground");
|
SET_STATE(State::Ground, "hit ground");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -73,6 +73,7 @@ public:
|
||||||
void setStepUpEnabled(bool enabled) { _stepUpEnabled = enabled; }
|
void setStepUpEnabled(bool enabled) { _stepUpEnabled = enabled; }
|
||||||
void computeNewVelocity(btScalar dt, btVector3& velocity);
|
void computeNewVelocity(btScalar dt, btVector3& velocity);
|
||||||
void computeNewVelocity(btScalar dt, glm::vec3& velocity);
|
void computeNewVelocity(btScalar dt, glm::vec3& velocity);
|
||||||
|
void setScaleFactor(btScalar scaleFactor) { _scaleFactor = scaleFactor; }
|
||||||
|
|
||||||
// HACK for legacy 'thrust' feature
|
// HACK for legacy 'thrust' feature
|
||||||
void setLinearAcceleration(const glm::vec3& acceleration) { _linearAcceleration = glmToBullet(acceleration); }
|
void setLinearAcceleration(const glm::vec3& acceleration) { _linearAcceleration = glmToBullet(acceleration); }
|
||||||
|
@ -185,7 +186,6 @@ protected:
|
||||||
|
|
||||||
btScalar _gravity { 0.0f };
|
btScalar _gravity { 0.0f };
|
||||||
|
|
||||||
btScalar _jumpSpeed;
|
|
||||||
btScalar _followTime;
|
btScalar _followTime;
|
||||||
btVector3 _followLinearDisplacement;
|
btVector3 _followLinearDisplacement;
|
||||||
btQuaternion _followAngularDisplacement;
|
btQuaternion _followAngularDisplacement;
|
||||||
|
@ -203,6 +203,8 @@ protected:
|
||||||
bool _flyingAllowed { true };
|
bool _flyingAllowed { true };
|
||||||
bool _collisionlessAllowed { true };
|
bool _collisionlessAllowed { true };
|
||||||
bool _collisionless { false };
|
bool _collisionless { false };
|
||||||
|
|
||||||
|
btScalar _scaleFactor { 1.0f };
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_CharacterController_h
|
#endif // hifi_CharacterController_h
|
||||||
|
|
|
@ -42,7 +42,15 @@ const glm::quat DEFAULT_AVATAR_LEFTFOOT_ROT { -0.40167322754859924f, 0.915459036
|
||||||
const glm::vec3 DEFAULT_AVATAR_RIGHTFOOT_POS { 0.08f, -0.96f, 0.029f };
|
const glm::vec3 DEFAULT_AVATAR_RIGHTFOOT_POS { 0.08f, -0.96f, 0.029f };
|
||||||
const glm::quat DEFAULT_AVATAR_RIGHTFOOT_ROT { -0.4016716778278351f, 0.9154615998268127f, 0.0053307069465518f, 0.023696165531873703f };
|
const glm::quat DEFAULT_AVATAR_RIGHTFOOT_ROT { -0.4016716778278351f, 0.9154615998268127f, 0.0053307069465518f, 0.023696165531873703f };
|
||||||
|
|
||||||
const float DEFAULT_AVATAR_MAX_WALKING_SPEED = 2.6f; // m/s
|
const float DEFAULT_AVATAR_MAX_WALKING_SPEED = 2.6f; // meters / second
|
||||||
const float DEFAULT_AVATAR_MAX_FLYING_SPEED = 30.0f; // m/s
|
const float DEFAULT_AVATAR_MAX_FLYING_SPEED = 30.0f; // meters / second
|
||||||
|
|
||||||
|
const float DEFAULT_AVATAR_GRAVITY = -5.0f; // meters / second^2
|
||||||
|
const float DEFAULT_AVATAR_JUMP_SPEED = 3.5f; // meters / second
|
||||||
|
const float DEFAULT_AVATAR_JUMP_HEIGHT = (DEFAULT_AVATAR_JUMP_SPEED * DEFAULT_AVATAR_JUMP_SPEED) / (2.0f * DEFAULT_AVATAR_GRAVITY); // meters
|
||||||
|
|
||||||
|
const float DEFAULT_AVATAR_FALL_HEIGHT = 20.0f; // meters
|
||||||
|
const float DEFAULT_AVATAR_MIN_HOVER_HEIGHT = 2.5f; // meters
|
||||||
|
|
||||||
|
|
||||||
#endif // hifi_AvatarConstants_h
|
#endif // hifi_AvatarConstants_h
|
||||||
|
|
Loading…
Reference in a new issue