mirror of
https://github.com/JulianGro/overte.git
synced 2025-08-08 01:48:33 +02:00
Merge pull request #13558 from danteruiz/fix-falling-through-floor
Fix falling through floor
This commit is contained in:
commit
1bd698a5dc
2 changed files with 7 additions and 10 deletions
|
@ -715,7 +715,7 @@ void MyAvatar::simulate(float deltaTime) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
bool isPhysicsEnabled = qApp->isPhysicsEnabled();
|
bool isPhysicsEnabled = qApp->isPhysicsEnabled();
|
||||||
_characterController.setFlyingAllowed(zoneAllowsFlying && (_enableFlying || !isPhysicsEnabled));
|
_characterController.setFlyingAllowed((zoneAllowsFlying && _enableFlying) || !isPhysicsEnabled);
|
||||||
_characterController.setCollisionlessAllowed(collisionlessAllowed);
|
_characterController.setCollisionlessAllowed(collisionlessAllowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -379,9 +379,6 @@ void CharacterController::setState(State desiredState, const char* reason) {
|
||||||
#else
|
#else
|
||||||
void CharacterController::setState(State desiredState) {
|
void CharacterController::setState(State desiredState) {
|
||||||
#endif
|
#endif
|
||||||
if (!_flyingAllowed && desiredState == State::Hover) {
|
|
||||||
desiredState = State::InAir;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (desiredState != _state) {
|
if (desiredState != _state) {
|
||||||
#ifdef DEBUG_STATE_CHANGE
|
#ifdef DEBUG_STATE_CHANGE
|
||||||
|
@ -747,7 +744,7 @@ void CharacterController::updateState() {
|
||||||
const float JUMP_SPEED = _scaleFactor * DEFAULT_AVATAR_JUMP_SPEED;
|
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 if (_flyingAllowed) {
|
||||||
btVector3 desiredVelocity = _targetVelocity;
|
btVector3 desiredVelocity = _targetVelocity;
|
||||||
if (desiredVelocity.length2() < MIN_TARGET_SPEED_SQUARED) {
|
if (desiredVelocity.length2() < MIN_TARGET_SPEED_SQUARED) {
|
||||||
desiredVelocity = btVector3(0.0f, 0.0f, 0.0f);
|
desiredVelocity = btVector3(0.0f, 0.0f, 0.0f);
|
||||||
|
@ -761,14 +758,17 @@ void CharacterController::updateState() {
|
||||||
// Transition to hover if we are above the fall threshold
|
// Transition to hover if we are above the fall threshold
|
||||||
SET_STATE(State::Hover, "above fall threshold");
|
SET_STATE(State::Hover, "above fall threshold");
|
||||||
}
|
}
|
||||||
|
} else if (!rayHasHit && !_hasSupport) {
|
||||||
|
SET_STATE(State::Hover, "no ground detected");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case State::Hover:
|
case State::Hover:
|
||||||
btScalar horizontalSpeed = (velocity - velocity.dot(_currentUp) * _currentUp).length();
|
btScalar horizontalSpeed = (velocity - velocity.dot(_currentUp) * _currentUp).length();
|
||||||
bool flyingFast = horizontalSpeed > (MAX_WALKING_SPEED * 0.75f);
|
bool flyingFast = horizontalSpeed > (MAX_WALKING_SPEED * 0.75f);
|
||||||
|
if (!_flyingAllowed && rayHasHit) {
|
||||||
if ((_floorDistance < MIN_HOVER_HEIGHT) && !jumpButtonHeld && !flyingFast) {
|
SET_STATE(State::InAir, "flying not allowed");
|
||||||
|
} else if ((_floorDistance < MIN_HOVER_HEIGHT) && !jumpButtonHeld && !flyingFast) {
|
||||||
SET_STATE(State::InAir, "near ground");
|
SET_STATE(State::InAir, "near ground");
|
||||||
} else if (((_floorDistance < FLY_TO_GROUND_THRESHOLD) || _hasSupport) && !flyingFast) {
|
} else if (((_floorDistance < FLY_TO_GROUND_THRESHOLD) || _hasSupport) && !flyingFast) {
|
||||||
SET_STATE(State::Ground, "touching ground");
|
SET_STATE(State::Ground, "touching ground");
|
||||||
|
@ -827,9 +827,6 @@ bool CharacterController::getRigidBodyLocation(glm::vec3& avatarRigidBodyPositio
|
||||||
void CharacterController::setFlyingAllowed(bool value) {
|
void CharacterController::setFlyingAllowed(bool value) {
|
||||||
if (value != _flyingAllowed) {
|
if (value != _flyingAllowed) {
|
||||||
_flyingAllowed = value;
|
_flyingAllowed = value;
|
||||||
if (!_flyingAllowed && _state == State::Hover) {
|
|
||||||
SET_STATE(State::InAir, "flying not allowed");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue