mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-22 03:40:49 +00:00
Use 3d coordinates to detect stuck
To able water and flying creatures move to player going up or down.
This commit is contained in:
parent
7b94183d83
commit
ad05de44ae
@ -76,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
|
||||
@ -123,19 +121,15 @@ namespace MWMechanics
|
||||
*/
|
||||
void ObstacleCheck::update(const MWWorld::Ptr& actor, float duration)
|
||||
{
|
||||
const MWWorld::Class& cls = actor.getClass();
|
||||
ESM::Position pos = actor.getRefData().getPosition();
|
||||
const osg::Vec3f pos = actor.getRefData().getPosition().asVec3();
|
||||
|
||||
if(mDistSameSpot == -1)
|
||||
mDistSameSpot = DIST_SAME_SPOT * cls.getSpeed(actor);
|
||||
if (mDistSameSpot == -1)
|
||||
mDistSameSpot = DIST_SAME_SPOT * actor.getClass().getSpeed(actor);
|
||||
|
||||
float distSameSpot = mDistSameSpot * duration;
|
||||
const float distSameSpot = mDistSameSpot * duration;
|
||||
const bool samePosition = (pos - mPrev).length2() < distSameSpot * distSameSpot;
|
||||
|
||||
bool samePosition = (osg::Vec2f(pos.pos[0], pos.pos[1]) - osg::Vec2f(mPrevX, mPrevY)).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…
x
Reference in New Issue
Block a user