mirror of
https://github.com/overte-org/overte.git
synced 2025-04-24 20:34:20 +02:00
Merge pull request #8787 from AndrewMeadows/recenter-above-ground
prevent avatar from recentering below ground
This commit is contained in:
commit
77e8082742
1 changed files with 9 additions and 0 deletions
|
@ -251,6 +251,15 @@ void MyAvatar::centerBody() {
|
|||
auto worldBodyPos = extractTranslation(worldBodyMatrix);
|
||||
auto worldBodyRot = glm::normalize(glm::quat_cast(worldBodyMatrix));
|
||||
|
||||
if (_characterController.getState() == CharacterController::State::Ground) {
|
||||
// the avatar's physical aspect thinks it is standing on something
|
||||
// therefore need to be careful to not "center" the body below the floor
|
||||
float downStep = glm::dot(worldBodyPos - getPosition(), _worldUpDirection);
|
||||
if (downStep < -0.5f * _characterController.getCapsuleHalfHeight() + _characterController.getCapsuleRadius()) {
|
||||
worldBodyPos -= downStep * _worldUpDirection;
|
||||
}
|
||||
}
|
||||
|
||||
// this will become our new position.
|
||||
setPosition(worldBodyPos);
|
||||
setOrientation(worldBodyRot);
|
||||
|
|
Loading…
Reference in a new issue