mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-21 11:09:41 +00:00
Try going right and left to "unstick" actor.
This commit is contained in:
parent
31d82b6b0c
commit
f2c9b9351f
4 changed files with 30 additions and 4 deletions
|
@ -114,8 +114,7 @@ void MWMechanics::AiPackage::evadeObstacles(const MWWorld::Ptr& actor, float dur
|
||||||
}
|
}
|
||||||
else // probably walking into another NPC
|
else // probably walking into another NPC
|
||||||
{
|
{
|
||||||
movement.mPosition[0] = 1;
|
mObstacleCheck.takeEvasiveAction(movement);
|
||||||
movement.mPosition[1] = 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { //Not stuck, so reset things
|
else { //Not stuck, so reset things
|
||||||
|
|
|
@ -435,8 +435,7 @@ namespace MWMechanics
|
||||||
{
|
{
|
||||||
// TODO: diagonal should have same animation as walk forward
|
// TODO: diagonal should have same animation as walk forward
|
||||||
// but doesn't seem to do that?
|
// but doesn't seem to do that?
|
||||||
movement.mPosition[0] = 1;
|
mObstacleCheck.takeEvasiveAction(movement);
|
||||||
movement.mPosition[1] = 0.1f;
|
|
||||||
}
|
}
|
||||||
mStuckCount++; // TODO: maybe no longer needed
|
mStuckCount++; // TODO: maybe no longer needed
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
#include "../mwworld/cellstore.hpp"
|
#include "../mwworld/cellstore.hpp"
|
||||||
|
|
||||||
|
#include "movement.hpp"
|
||||||
|
|
||||||
namespace MWMechanics
|
namespace MWMechanics
|
||||||
{
|
{
|
||||||
// NOTE: determined empirically but probably need further tweaking
|
// NOTE: determined empirically but probably need further tweaking
|
||||||
|
@ -67,6 +69,7 @@ namespace MWMechanics
|
||||||
, mStuckDuration(0)
|
, mStuckDuration(0)
|
||||||
, mEvadeDuration(0)
|
, mEvadeDuration(0)
|
||||||
, mDistSameSpot(-1) // avoid calculating it each time
|
, mDistSameSpot(-1) // avoid calculating it each time
|
||||||
|
, mEvadeDirection(1.0f)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,6 +158,7 @@ namespace MWMechanics
|
||||||
/* FALL THROUGH */
|
/* FALL THROUGH */
|
||||||
case State_Evade:
|
case State_Evade:
|
||||||
{
|
{
|
||||||
|
chooseEvasionDirection(samePosition);
|
||||||
mEvadeDuration += duration;
|
mEvadeDuration += duration;
|
||||||
if(mEvadeDuration < DURATION_TO_EVADE)
|
if(mEvadeDuration < DURATION_TO_EVADE)
|
||||||
return true;
|
return true;
|
||||||
|
@ -169,4 +173,20 @@ namespace MWMechanics
|
||||||
}
|
}
|
||||||
return false; // no obstacles to evade (yet)
|
return false; // no obstacles to evade (yet)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ObstacleCheck::takeEvasiveAction(MWMechanics::Movement& actorMovement)
|
||||||
|
{
|
||||||
|
actorMovement.mPosition[0] = mEvadeDirection;
|
||||||
|
actorMovement.mPosition[1] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObstacleCheck::chooseEvasionDirection(bool samePosition)
|
||||||
|
{
|
||||||
|
// change direction if attempt didn't work
|
||||||
|
if (samePosition && (0 < mEvadeDuration))
|
||||||
|
{
|
||||||
|
mEvadeDirection = mEvadeDirection == 1.0f ? -1.0f : 1.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@ namespace MWWorld
|
||||||
|
|
||||||
namespace MWMechanics
|
namespace MWMechanics
|
||||||
{
|
{
|
||||||
|
struct Movement;
|
||||||
|
|
||||||
/// NOTE: determined empirically based on in-game behaviour
|
/// NOTE: determined empirically based on in-game behaviour
|
||||||
static const float MIN_DIST_TO_DOOR_SQUARED = 128*128;
|
static const float MIN_DIST_TO_DOOR_SQUARED = 128*128;
|
||||||
|
|
||||||
|
@ -36,6 +38,9 @@ namespace MWMechanics
|
||||||
// should be taken
|
// should be taken
|
||||||
bool check(const MWWorld::Ptr& actor, float duration);
|
bool check(const MWWorld::Ptr& actor, float duration);
|
||||||
|
|
||||||
|
// change direction to try to fix "stuck" actor
|
||||||
|
void takeEvasiveAction(MWMechanics::Movement& actorMovement);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// for checking if we're stuck (ignoring Z axis)
|
// for checking if we're stuck (ignoring Z axis)
|
||||||
|
@ -53,6 +58,9 @@ namespace MWMechanics
|
||||||
float mStuckDuration; // accumulate time here while in same spot
|
float mStuckDuration; // accumulate time here while in same spot
|
||||||
float mEvadeDuration;
|
float mEvadeDuration;
|
||||||
float mDistSameSpot; // take account of actor's speed
|
float mDistSameSpot; // take account of actor's speed
|
||||||
|
float mEvadeDirection;
|
||||||
|
|
||||||
|
void chooseEvasionDirection(bool samePosition);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue