mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-19 19:09:49 +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
|
||||
{
|
||||
movement.mPosition[0] = 1;
|
||||
movement.mPosition[1] = 1;
|
||||
mObstacleCheck.takeEvasiveAction(movement);
|
||||
}
|
||||
}
|
||||
else { //Not stuck, so reset things
|
||||
|
|
|
@ -435,8 +435,7 @@ namespace MWMechanics
|
|||
{
|
||||
// TODO: diagonal should have same animation as walk forward
|
||||
// but doesn't seem to do that?
|
||||
movement.mPosition[0] = 1;
|
||||
movement.mPosition[1] = 0.1f;
|
||||
mObstacleCheck.takeEvasiveAction(movement);
|
||||
}
|
||||
mStuckCount++; // TODO: maybe no longer needed
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include "../mwworld/class.hpp"
|
||||
#include "../mwworld/cellstore.hpp"
|
||||
|
||||
#include "movement.hpp"
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
// NOTE: determined empirically but probably need further tweaking
|
||||
|
@ -67,6 +69,7 @@ namespace MWMechanics
|
|||
, mStuckDuration(0)
|
||||
, mEvadeDuration(0)
|
||||
, mDistSameSpot(-1) // avoid calculating it each time
|
||||
, mEvadeDirection(1.0f)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -155,6 +158,7 @@ namespace MWMechanics
|
|||
/* FALL THROUGH */
|
||||
case State_Evade:
|
||||
{
|
||||
chooseEvasionDirection(samePosition);
|
||||
mEvadeDuration += duration;
|
||||
if(mEvadeDuration < DURATION_TO_EVADE)
|
||||
return true;
|
||||
|
@ -169,4 +173,20 @@ namespace MWMechanics
|
|||
}
|
||||
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
|
||||
{
|
||||
struct Movement;
|
||||
|
||||
/// NOTE: determined empirically based on in-game behaviour
|
||||
static const float MIN_DIST_TO_DOOR_SQUARED = 128*128;
|
||||
|
||||
|
@ -36,6 +38,9 @@ namespace MWMechanics
|
|||
// should be taken
|
||||
bool check(const MWWorld::Ptr& actor, float duration);
|
||||
|
||||
// change direction to try to fix "stuck" actor
|
||||
void takeEvasiveAction(MWMechanics::Movement& actorMovement);
|
||||
|
||||
private:
|
||||
|
||||
// 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 mEvadeDuration;
|
||||
float mDistSameSpot; // take account of actor's speed
|
||||
float mEvadeDirection;
|
||||
|
||||
void chooseEvasionDirection(bool samePosition);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue