mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-23 15:40:42 +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
|
return MWWorld::Ptr(); // none found
|
||||||
}
|
}
|
||||||
|
|
||||||
ObstacleCheck::ObstacleCheck():
|
ObstacleCheck::ObstacleCheck()
|
||||||
mPrevX(0) // to see if the moved since last time
|
: mWalkState(State_Norm)
|
||||||
, mPrevY(0)
|
|
||||||
, mWalkState(State_Norm)
|
|
||||||
, mStuckDuration(0)
|
, mStuckDuration(0)
|
||||||
, mEvadeDuration(0)
|
, mEvadeDuration(0)
|
||||||
, mDistSameSpot(-1) // avoid calculating it each time
|
, mDistSameSpot(-1) // avoid calculating it each time
|
||||||
@ -123,19 +121,15 @@ namespace MWMechanics
|
|||||||
*/
|
*/
|
||||||
void ObstacleCheck::update(const MWWorld::Ptr& actor, float duration)
|
void ObstacleCheck::update(const MWWorld::Ptr& actor, float duration)
|
||||||
{
|
{
|
||||||
const MWWorld::Class& cls = actor.getClass();
|
const osg::Vec3f pos = actor.getRefData().getPosition().asVec3();
|
||||||
ESM::Position pos = actor.getRefData().getPosition();
|
|
||||||
|
|
||||||
if(mDistSameSpot == -1)
|
if (mDistSameSpot == -1)
|
||||||
mDistSameSpot = DIST_SAME_SPOT * cls.getSpeed(actor);
|
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;
|
mPrev = pos;
|
||||||
|
|
||||||
// update position
|
|
||||||
mPrevX = pos.pos[0];
|
|
||||||
mPrevY = pos.pos[1];
|
|
||||||
|
|
||||||
switch(mWalkState)
|
switch(mWalkState)
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef OPENMW_MECHANICS_OBSTACLE_H
|
#ifndef OPENMW_MECHANICS_OBSTACLE_H
|
||||||
#define OPENMW_MECHANICS_OBSTACLE_H
|
#define OPENMW_MECHANICS_OBSTACLE_H
|
||||||
|
|
||||||
|
#include <osg/Vec3f>
|
||||||
|
|
||||||
namespace MWWorld
|
namespace MWWorld
|
||||||
{
|
{
|
||||||
class Ptr;
|
class Ptr;
|
||||||
@ -37,9 +39,8 @@ namespace MWMechanics
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// for checking if we're stuck (ignoring Z axis)
|
// for checking if we're stuck
|
||||||
float mPrevX;
|
osg::Vec3f mPrev;
|
||||||
float mPrevY;
|
|
||||||
|
|
||||||
// directions to try moving in when get stuck
|
// directions to try moving in when get stuck
|
||||||
static const float evadeDirections[NUM_EVADE_DIRECTIONS][2];
|
static const float evadeDirections[NUM_EVADE_DIRECTIONS][2];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user