1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 20:19:57 +00:00

Fix a bug that was triggered with multi mark mod.

When a script calls SetPos for x,y,z in sequence on an actor, we need to make sure
that the actor will not spawn under ground at x,y coordinates.
Now that change of coordinates are cumulated and applied all at once, we
need to account for the whole offset.
To this end move the terrain height check inside of Actor class.
This commit is contained in:
fredzio 2021-03-31 19:34:06 +02:00
parent a576824bcf
commit 9cae7882dd
2 changed files with 11 additions and 11 deletions

View file

@ -3,6 +3,8 @@
#include <BulletCollision/CollisionShapes/btBoxShape.h> #include <BulletCollision/CollisionShapes/btBoxShape.h>
#include <BulletCollision/CollisionDispatch/btCollisionWorld.h> #include <BulletCollision/CollisionDispatch/btCollisionWorld.h>
#include <apps/openmw/mwmechanics/actorutil.hpp>
#include <apps/openmw/mwworld/cellstore.hpp>
#include <components/sceneutil/positionattitudetransform.hpp> #include <components/sceneutil/positionattitudetransform.hpp>
#include <components/resource/bulletshape.hpp> #include <components/resource/bulletshape.hpp>
#include <components/debug/debuglog.hpp> #include <components/debug/debuglog.hpp>
@ -195,6 +197,15 @@ void Actor::applyOffsetChange()
{ {
if (mPositionOffset.length() == 0) if (mPositionOffset.length() == 0)
return; return;
if (mPositionOffset.z() != 0)
{
// Often, offset are set in sequence x, y, z
// We don't want actors to be moved under the ground
// Check terrain height at new coordinate and update z offset if necessary
const auto pos = mWorldPosition + mPositionOffset;
const auto terrainHeight = mPtr.getCell()->isExterior() ? MWBase::Environment::get().getWorld()->getTerrainHeightAt(pos) : -std::numeric_limits<float>::max();
mPositionOffset.z() = std::max(pos.z(), terrainHeight) - mWorldPosition.z();
}
mWorldPosition += mPositionOffset; mWorldPosition += mPositionOffset;
mPosition += mPositionOffset; mPosition += mPositionOffset;
mPreviousPosition += mPositionOffset; mPreviousPosition += mPositionOffset;

View file

@ -284,17 +284,6 @@ namespace MWScript
} }
else if(axis == "z") else if(axis == "z")
{ {
// We should not place actors under ground
if (ptr.getClass().isActor())
{
float terrainHeight = -std::numeric_limits<float>::max();
if (ptr.getCell()->isExterior())
terrainHeight = MWBase::Environment::get().getWorld()->getTerrainHeightAt(curPos);
if (pos < terrainHeight)
pos = terrainHeight;
}
newPos[2] = pos; newPos[2] = pos;
} }
else else