1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2024-12-29 12:20:41 +00:00

Change the comparison of positions to avoid a problem if both positions are large numbers.

This commit is contained in:
Mads Buvik Sandvei 2023-12-04 20:36:22 +01:00
parent 0037fd78c1
commit 26817e9cc5

View File

@ -202,7 +202,8 @@ namespace MWPhysics
for (int iterations = 0; iterations < sMaxIterations && remainingTime > 0.0001f; ++iterations)
{
osg::Vec3f nextpos = newPosition + velocity * remainingTime;
osg::Vec3f diff = velocity * remainingTime;
osg::Vec3f nextpos = newPosition + diff;
bool underwater = newPosition.z() < swimlevel;
// If not able to fly, don't allow to swim up into the air
@ -214,7 +215,9 @@ namespace MWPhysics
continue; // velocity updated, calculate nextpos again
}
if ((newPosition - nextpos).length2() > std::numeric_limits<float>::epsilon())
// Note, we use an epsilon of 1e-6 instead of std::numeric_limits<float>::epsilon() to avoid doing extremely
// small steps. But if we make it any larger we'll start rejecting subtle movements from e.g. idle animations.
if (diff.length2() > 1e-6 && (newPosition - nextpos).length2() > 1e-6)
{
// trace to where character would go if there were no obstructions
tracer.doTrace(actor.mCollisionObject, newPosition, nextpos, collisionWorld, actor.mIsOnGround);