mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 13:58:51 +02:00
Add function for calculating direction in MyAvatar.
This commit is contained in:
parent
d3c1843d45
commit
1e10afe762
2 changed files with 28 additions and 19 deletions
|
@ -3278,21 +3278,7 @@ static float scaleSpeedByDirection(const glm::vec2 velocityDirection, const floa
|
||||||
return scaledSpeed;
|
return scaledSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAvatar::updateActionMotor(float deltaTime) {
|
glm::vec3 MyAvatar::calculateScaledDirection(){
|
||||||
bool thrustIsPushing = (glm::length2(_thrust) > EPSILON);
|
|
||||||
bool scriptedMotorIsPushing = (_motionBehaviors & AVATAR_MOTION_SCRIPTED_MOTOR_ENABLED)
|
|
||||||
&& _scriptedMotorTimescale < MAX_CHARACTER_MOTOR_TIMESCALE;
|
|
||||||
_isBeingPushed = thrustIsPushing || scriptedMotorIsPushing;
|
|
||||||
if (_isPushing || _isBeingPushed) {
|
|
||||||
// we don't want the motor to brake if a script is pushing the avatar around
|
|
||||||
// (we assume the avatar is driving itself via script)
|
|
||||||
_isBraking = false;
|
|
||||||
} else {
|
|
||||||
float speed = glm::length(_actionMotorVelocity);
|
|
||||||
const float MIN_ACTION_BRAKE_SPEED = 0.1f;
|
|
||||||
_isBraking = _wasPushing || (_isBraking && speed > MIN_ACTION_BRAKE_SPEED);
|
|
||||||
}
|
|
||||||
|
|
||||||
CharacterController::State state = _characterController.getState();
|
CharacterController::State state = _characterController.getState();
|
||||||
|
|
||||||
// compute action input
|
// compute action input
|
||||||
|
@ -3318,6 +3304,7 @@ void MyAvatar::updateActionMotor(float deltaTime) {
|
||||||
if (state == CharacterController::State::Hover ||
|
if (state == CharacterController::State::Hover ||
|
||||||
_characterController.computeCollisionGroup() == BULLET_COLLISION_GROUP_COLLISIONLESS) {
|
_characterController.computeCollisionGroup() == BULLET_COLLISION_GROUP_COLLISIONLESS) {
|
||||||
glm::vec3 up = (getDriveKey(TRANSLATE_Y)) * IDENTITY_UP;
|
glm::vec3 up = (getDriveKey(TRANSLATE_Y)) * IDENTITY_UP;
|
||||||
|
up /= glm::length(up);
|
||||||
direction += up;
|
direction += up;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3325,13 +3312,34 @@ void MyAvatar::updateActionMotor(float deltaTime) {
|
||||||
float directionLength = glm::length(direction);
|
float directionLength = glm::length(direction);
|
||||||
_isPushing = directionLength > EPSILON;
|
_isPushing = directionLength > EPSILON;
|
||||||
|
|
||||||
// normalize direction
|
|
||||||
if (_isPushing) {
|
if (_isPushing) {
|
||||||
direction /= directionLength;
|
direction;
|
||||||
} else {
|
} else {
|
||||||
direction = Vectors::ZERO;
|
direction = Vectors::ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyAvatar::updateActionMotor(float deltaTime) {
|
||||||
|
bool thrustIsPushing = (glm::length2(_thrust) > EPSILON);
|
||||||
|
bool scriptedMotorIsPushing = (_motionBehaviors & AVATAR_MOTION_SCRIPTED_MOTOR_ENABLED)
|
||||||
|
&& _scriptedMotorTimescale < MAX_CHARACTER_MOTOR_TIMESCALE;
|
||||||
|
_isBeingPushed = thrustIsPushing || scriptedMotorIsPushing;
|
||||||
|
if (_isPushing || _isBeingPushed) {
|
||||||
|
// we don't want the motor to brake if a script is pushing the avatar around
|
||||||
|
// (we assume the avatar is driving itself via script)
|
||||||
|
_isBraking = false;
|
||||||
|
} else {
|
||||||
|
float speed = glm::length(_actionMotorVelocity);
|
||||||
|
const float MIN_ACTION_BRAKE_SPEED = 0.1f;
|
||||||
|
_isBraking = _wasPushing || (_isBraking && speed > MIN_ACTION_BRAKE_SPEED);
|
||||||
|
}
|
||||||
|
|
||||||
|
CharacterController::State state = _characterController.getState();
|
||||||
|
|
||||||
|
glm::vec3 direction = calculateScaledDirection();
|
||||||
|
|
||||||
if (state == CharacterController::State::Hover) {
|
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
|
// we're flying --> complex acceleration curve that builds on top of current motor speed and caps at some max speed
|
||||||
|
|
||||||
|
|
|
@ -1772,6 +1772,7 @@ private:
|
||||||
|
|
||||||
// private methods
|
// private methods
|
||||||
void updateOrientation(float deltaTime);
|
void updateOrientation(float deltaTime);
|
||||||
|
glm::vec3 calculateScaledDirection();
|
||||||
void updateActionMotor(float deltaTime);
|
void updateActionMotor(float deltaTime);
|
||||||
void updatePosition(float deltaTime);
|
void updatePosition(float deltaTime);
|
||||||
void updateCollisionSound(const glm::vec3& penetration, float deltaTime, float frequency);
|
void updateCollisionSound(const glm::vec3& penetration, float deltaTime, float frequency);
|
||||||
|
|
Loading…
Reference in a new issue