diff --git a/apps/openmw/mwmp/DedicatedActor.cpp b/apps/openmw/mwmp/DedicatedActor.cpp index 5eaebadf6..978a94471 100644 --- a/apps/openmw/mwmp/DedicatedActor.cpp +++ b/apps/openmw/mwmp/DedicatedActor.cpp @@ -65,9 +65,12 @@ void DedicatedActor::move(float dt) ESM::Position refPos = ptr.getRefData().getPosition(); MWBase::World *world = MWBase::Environment::get().getWorld(); + // Apply interpolation only if the position hasn't changed too much from last time + bool shouldInterpolate = abs(position.pos[0] - refPos.pos[0]) < 4 && abs(position.pos[1] - refPos.pos[1]) < 4 && abs(position.pos[2] - refPos.pos[2]) < 4; + // Don't apply linear interpolation if the DedicatedActor has just gone through a cell change, because // the interpolated position will be invalid, causing a slight hopping glitch - if (!hasChangedCell) + if (shouldInterpolate && !hasChangedCell) { static const int timeMultiplier = 15; osg::Vec3f lerp = Main::get().getMechanicsHelper()->getLinearInterpolation(refPos.asVec3(), position.asVec3(), dt * timeMultiplier); diff --git a/apps/openmw/mwmp/DedicatedPlayer.cpp b/apps/openmw/mwmp/DedicatedPlayer.cpp index ee2bf7d8e..13c20173c 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.cpp +++ b/apps/openmw/mwmp/DedicatedPlayer.cpp @@ -94,6 +94,10 @@ void DedicatedPlayer::move(float dt) ESM::Position refPos = ptr.getRefData().getPosition(); MWBase::World *world = MWBase::Environment::get().getWorld(); + // Apply interpolation only if the position hasn't changed too much from last time + bool shouldInterpolate = abs(position.pos[0] - refPos.pos[0]) < 4 && abs(position.pos[1] - refPos.pos[1]) < 4 && abs(position.pos[2] - refPos.pos[2]) < 4; + + if (shouldInterpolate) { static const int timeMultiplier = 15; osg::Vec3f lerp = Main::get().getMechanicsHelper()->getLinearInterpolation(refPos.asVec3(), position.asVec3(), dt * timeMultiplier); @@ -103,6 +107,10 @@ void DedicatedPlayer::move(float dt) world->moveObject(ptr, refPos.pos[0], refPos.pos[1], refPos.pos[2]); } + else + { + world->moveObject(ptr, position.pos[0], position.pos[1], position.pos[2]); + } MWMechanics::Movement *move = &ptr.getClass().getMovementSettings(ptr); move->mPosition[0] = direction.pos[0];