1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 15:29:55 +00:00

ObstacleCheck: fix the framerate not being taken into account

This commit is contained in:
scrawl 2015-11-09 20:21:25 +01:00
parent 801dc8eee3
commit caa523a959

View file

@ -11,7 +11,7 @@
namespace MWMechanics
{
// NOTE: determined empirically but probably need further tweaking
static const float DIST_SAME_SPOT = 1.8f;
static const float DIST_SAME_SPOT = 0.72f;
static const float DURATION_SAME_SPOT = 1.0f;
static const float DURATION_TO_EVADE = 0.4f;
@ -114,19 +114,22 @@ namespace MWMechanics
* t = how long before considered stuck
* u = how long to move sideways
*
* DIST_SAME_SPOT is calibrated for movement speed of around 150.
* A rat has walking speed of around 30, so we need to adjust for
* that.
*/
bool ObstacleCheck::check(const MWWorld::Ptr& actor, float duration)
{
const MWWorld::Class& cls = actor.getClass();
ESM::Position pos = actor.getRefData().getPosition();
if(mDistSameSpot == -1)
mDistSameSpot = DIST_SAME_SPOT * (cls.getSpeed(actor) / 150);
// actors can move at most 60 fps (the physics framerate).
// the max() can be removed if we implement physics interpolation.
float movementDuration = std::max(1/60.f, duration);
bool samePosition = (osg::Vec2f(pos.pos[0], pos.pos[1]) - osg::Vec2f(mPrevX, mPrevY)).length2() < mDistSameSpot * mDistSameSpot;
if(mDistSameSpot == -1)
mDistSameSpot = DIST_SAME_SPOT * cls.getSpeed(actor);
float distSameSpot = mDistSameSpot * movementDuration;
bool samePosition = (osg::Vec2f(pos.pos[0], pos.pos[1]) - osg::Vec2f(mPrevX, mPrevY)).length2() < distSameSpot * distSameSpot;
// update position
mPrevX = pos.pos[0];