mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 03:50:40 +02:00
prevent avatar from recentering below ground
This commit is contained in:
parent
58d4eb7452
commit
867fc3ccbf
1 changed files with 9 additions and 0 deletions
|
@ -247,6 +247,15 @@ void MyAvatar::centerBody() {
|
||||||
auto worldBodyPos = extractTranslation(worldBodyMatrix);
|
auto worldBodyPos = extractTranslation(worldBodyMatrix);
|
||||||
auto worldBodyRot = glm::normalize(glm::quat_cast(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.
|
// this will become our new position.
|
||||||
setPosition(worldBodyPos);
|
setPosition(worldBodyPos);
|
||||||
setOrientation(worldBodyRot);
|
setOrientation(worldBodyRot);
|
||||||
|
|
Loading…
Reference in a new issue