mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-23 12:15:30 +02:00
fix driving motion of collisionless avatars
This commit is contained in:
parent
c47e26174c
commit
94ee6d6838
2 changed files with 24 additions and 11 deletions
|
@ -1883,8 +1883,9 @@ void MyAvatar::updateActionMotor(float deltaTime) {
|
||||||
|
|
||||||
glm::vec3 direction = forward + right;
|
glm::vec3 direction = forward + right;
|
||||||
CharacterController::State state = _characterController.getState();
|
CharacterController::State state = _characterController.getState();
|
||||||
if (state == CharacterController::State::Hover) {
|
if (state == CharacterController::State::Hover ||
|
||||||
// we're flying --> support vertical motion
|
_characterController.getCollisionGroup() == BULLET_COLLISION_GROUP_COLLISIONLESS) {
|
||||||
|
// we can fly --> support vertical motion
|
||||||
glm::vec3 up = (getDriveKey(TRANSLATE_Y)) * IDENTITY_UP;
|
glm::vec3 up = (getDriveKey(TRANSLATE_Y)) * IDENTITY_UP;
|
||||||
direction += up;
|
direction += up;
|
||||||
}
|
}
|
||||||
|
|
|
@ -400,8 +400,12 @@ void CharacterController::handleChangedCollisionGroup() {
|
||||||
}
|
}
|
||||||
_pendingFlags &= ~PENDING_FLAG_UPDATE_COLLISION_GROUP;
|
_pendingFlags &= ~PENDING_FLAG_UPDATE_COLLISION_GROUP;
|
||||||
|
|
||||||
if (_state != State::Hover && _rigidBody) {
|
if (_collisionGroup == BULLET_COLLISION_GROUP_COLLISIONLESS) {
|
||||||
_gravity = _collisionGroup == BULLET_COLLISION_GROUP_COLLISIONLESS ? 0.0f : DEFAULT_CHARACTER_GRAVITY;
|
_gravity = 0.0f;
|
||||||
|
} else if (_state != State::Hover) {
|
||||||
|
_gravity = (_collisionGroup == BULLET_COLLISION_GROUP_COLLISIONLESS) ? 0.0f : DEFAULT_CHARACTER_GRAVITY;
|
||||||
|
}
|
||||||
|
if (_rigidBody) {
|
||||||
_rigidBody->setGravity(_gravity * _currentUp);
|
_rigidBody->setGravity(_gravity * _currentUp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -630,8 +634,12 @@ void CharacterController::updateState() {
|
||||||
// rayStart is at center of bottom sphere
|
// rayStart is at center of bottom sphere
|
||||||
btVector3 rayStart = _position;
|
btVector3 rayStart = _position;
|
||||||
|
|
||||||
// rayEnd is straight down MAX_FALL_HEIGHT
|
btScalar rayLength = _radius;
|
||||||
btScalar rayLength = _radius + MAX_FALL_HEIGHT;
|
if (_collisionGroup == BULLET_COLLISION_GROUP_MY_AVATAR) {
|
||||||
|
rayLength += MAX_FALL_HEIGHT;
|
||||||
|
} else {
|
||||||
|
rayLength += MIN_HOVER_HEIGHT;
|
||||||
|
}
|
||||||
btVector3 rayEnd = rayStart - rayLength * _currentUp;
|
btVector3 rayEnd = rayStart - rayLength * _currentUp;
|
||||||
|
|
||||||
ClosestNotMe rayCallback(_rigidBody);
|
ClosestNotMe rayCallback(_rigidBody);
|
||||||
|
@ -663,6 +671,7 @@ void CharacterController::updateState() {
|
||||||
btVector3 velocity = _preSimulationVelocity;
|
btVector3 velocity = _preSimulationVelocity;
|
||||||
|
|
||||||
// disable normal state transitions while collisionless
|
// disable normal state transitions while collisionless
|
||||||
|
const btScalar MAX_WALKING_SPEED = 2.65f;
|
||||||
if (_collisionGroup == BULLET_COLLISION_GROUP_MY_AVATAR) {
|
if (_collisionGroup == BULLET_COLLISION_GROUP_MY_AVATAR) {
|
||||||
switch (_state) {
|
switch (_state) {
|
||||||
case State::Ground:
|
case State::Ground:
|
||||||
|
@ -703,9 +712,8 @@ void CharacterController::updateState() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case State::Hover:
|
case State::Hover:
|
||||||
btVector3 actualHorizVelocity = velocity - velocity.dot(_currentUp) * _currentUp;
|
btScalar horizontalSpeed = (velocity - velocity.dot(_currentUp) * _currentUp).length();
|
||||||
const btScalar MAX_WALKING_SPEED = 2.5f;
|
bool flyingFast = _state == State::Hover && horizontalSpeed > (MAX_WALKING_SPEED * 0.75f);
|
||||||
bool flyingFast = _state == State::Hover && actualHorizVelocity.length() > (MAX_WALKING_SPEED * 0.75f);
|
|
||||||
|
|
||||||
if ((_floorDistance < MIN_HOVER_HEIGHT) &&
|
if ((_floorDistance < MIN_HOVER_HEIGHT) &&
|
||||||
!(jumpButtonHeld || flyingFast || (now - _jumpButtonDownStartTime) > JUMP_TO_HOVER_PERIOD)) {
|
!(jumpButtonHeld || flyingFast || (now - _jumpButtonDownStartTime) > JUMP_TO_HOVER_PERIOD)) {
|
||||||
|
@ -716,9 +724,13 @@ void CharacterController::updateState() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// in collisionless state switch only between Ground and Hover states
|
// when collisionless: only switch between State::Ground and State::Hover
|
||||||
if (rayHasHit) {
|
if (rayHasHit) {
|
||||||
|
if (velocity.length() > (MAX_WALKING_SPEED)) {
|
||||||
|
SET_STATE(State::Hover, "collisionless in air");
|
||||||
|
} else {
|
||||||
SET_STATE(State::Ground, "collisionless above ground");
|
SET_STATE(State::Ground, "collisionless above ground");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
SET_STATE(State::Hover, "collisionless in air");
|
SET_STATE(State::Hover, "collisionless in air");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue