mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 19:19:56 +00:00
Merge pull request #2500 from elsid/horker_evade_stuck
Use 3d coordinates to detect stuck (bug #5127)
This commit is contained in:
commit
ee5b81470c
2 changed files with 10 additions and 19 deletions
|
@ -2,8 +2,6 @@
|
|||
|
||||
#include <components/sceneutil/positionattitudetransform.hpp>
|
||||
|
||||
#include "../mwbase/world.hpp"
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwworld/class.hpp"
|
||||
#include "../mwworld/cellstore.hpp"
|
||||
|
||||
|
@ -78,10 +76,8 @@ namespace MWMechanics
|
|||
return MWWorld::Ptr(); // none found
|
||||
}
|
||||
|
||||
ObstacleCheck::ObstacleCheck():
|
||||
mPrevX(0) // to see if the moved since last time
|
||||
, mPrevY(0)
|
||||
, mWalkState(State_Norm)
|
||||
ObstacleCheck::ObstacleCheck()
|
||||
: mWalkState(State_Norm)
|
||||
, mStuckDuration(0)
|
||||
, mEvadeDuration(0)
|
||||
, mDistSameSpot(-1) // avoid calculating it each time
|
||||
|
@ -125,21 +121,15 @@ namespace MWMechanics
|
|||
*/
|
||||
void ObstacleCheck::update(const MWWorld::Ptr& actor, float duration)
|
||||
{
|
||||
const ESM::Position pos = actor.getRefData().getPosition();
|
||||
const osg::Vec3f pos = actor.getRefData().getPosition().asVec3();
|
||||
|
||||
if (mDistSameSpot == -1)
|
||||
{
|
||||
const osg::Vec3f halfExtents = MWBase::Environment::get().getWorld()->getHalfExtents(actor);
|
||||
mDistSameSpot = DIST_SAME_SPOT * actor.getClass().getSpeed(actor) + 1.2 * std::max(halfExtents.x(), halfExtents.y());
|
||||
}
|
||||
mDistSameSpot = DIST_SAME_SPOT * actor.getClass().getSpeed(actor);
|
||||
|
||||
const float distSameSpot = mDistSameSpot * duration;
|
||||
const float squaredMovedDistance = (osg::Vec2f(pos.pos[0], pos.pos[1]) - osg::Vec2f(mPrevX, mPrevY)).length2();
|
||||
const bool samePosition = squaredMovedDistance < distSameSpot * distSameSpot;
|
||||
const bool samePosition = (pos - mPrev).length2() < distSameSpot * distSameSpot;
|
||||
|
||||
// update position
|
||||
mPrevX = pos.pos[0];
|
||||
mPrevY = pos.pos[1];
|
||||
mPrev = pos;
|
||||
|
||||
switch(mWalkState)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef OPENMW_MECHANICS_OBSTACLE_H
|
||||
#define OPENMW_MECHANICS_OBSTACLE_H
|
||||
|
||||
#include <osg/Vec3f>
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
class Ptr;
|
||||
|
@ -37,9 +39,8 @@ namespace MWMechanics
|
|||
|
||||
private:
|
||||
|
||||
// for checking if we're stuck (ignoring Z axis)
|
||||
float mPrevX;
|
||||
float mPrevY;
|
||||
// for checking if we're stuck
|
||||
osg::Vec3f mPrev;
|
||||
|
||||
// directions to try moving in when get stuck
|
||||
static const float evadeDirections[NUM_EVADE_DIRECTIONS][2];
|
||||
|
|
Loading…
Reference in a new issue