1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 03:12:36 +01:00

Prevent characters falling through the ground when placed

This was occuring when loading saves created in portland
This commit is contained in:
Daniel Evans 2018-01-15 01:12:51 +00:00
parent 1ed182c3f2
commit 869f09ba01

View File

@ -389,16 +389,15 @@ void CharacterObject::updateCharacter(float dt) {
} }
void CharacterObject::setPosition(const glm::vec3& pos) { void CharacterObject::setPosition(const glm::vec3& pos) {
auto realPos = pos;
if (physCharacter) { if (physCharacter) {
btVector3 bpos(pos.x, pos.y, pos.z); if (pos.z <= -99.f) {
if (std::abs(-100.f - pos.z) < 0.01f) { realPos = engine->getGroundAtPosition(pos);
// Find the ground position
auto gpos = engine->getGroundAtPosition(pos);
bpos.setZ(gpos.z + 1.f);
} }
btVector3 bpos(realPos.x, realPos.y, realPos.z + 1.0f);
physCharacter->warp(bpos); physCharacter->warp(bpos);
} }
position = pos; position = realPos;
getClump()->getFrame()->setTranslation(pos); getClump()->getFrame()->setTranslation(pos);
} }