|
|
|
@ -51,14 +51,17 @@ bool MWMechanics::AiAvoidDoor::execute (const MWWorld::Ptr& actor,float duration
|
|
|
|
|
ESM::Position tPos = mDoorPtr.getRefData().getPosition(); //Position of the door
|
|
|
|
|
float x = pos.pos[0] - tPos.pos[0];
|
|
|
|
|
float y = pos.pos[1] - tPos.pos[1];
|
|
|
|
|
float dirToDoor = std::atan2(x,y) + pos.rot[2] + mAdjAngle; //Calculates the direction to the door, relative to the direction of the NPC
|
|
|
|
|
// For example, if the NPC is directly facing the door this will be pi/2
|
|
|
|
|
|
|
|
|
|
// Make actor move away from the door
|
|
|
|
|
actor.getClass().getMovementSettings(actor).mPosition[1] = -1 * std::sin(dirToDoor); //I knew I'd use trig someday
|
|
|
|
|
actor.getClass().getMovementSettings(actor).mPosition[0] = -1 * std::cos(dirToDoor);
|
|
|
|
|
actor.getClass().getCreatureStats(actor).setMovementFlag(CreatureStats::Flag_Run, true);
|
|
|
|
|
|
|
|
|
|
//Make all nearby actors also avoid the door
|
|
|
|
|
// Turn away from the door and move when turn completed
|
|
|
|
|
if (zTurn(actor, Ogre::Radian(std::atan2(x,y) + mAdjAngle), Ogre::Degree(5)))
|
|
|
|
|
actor.getClass().getMovementSettings(actor).mPosition[1] = 1;
|
|
|
|
|
else
|
|
|
|
|
actor.getClass().getMovementSettings(actor).mPosition[1] = 0;
|
|
|
|
|
actor.getClass().getMovementSettings(actor).mPosition[0] = 0;
|
|
|
|
|
|
|
|
|
|
// Make all nearby actors also avoid the door
|
|
|
|
|
std::vector<MWWorld::Ptr> actors;
|
|
|
|
|
MWBase::Environment::get().getMechanicsManager()->getActorsInRange(Ogre::Vector3(pos.pos[0],pos.pos[1],pos.pos[2]),100,actors);
|
|
|
|
|
for(std::vector<MWWorld::Ptr>::iterator it = actors.begin(); it != actors.end(); it++) {
|
|
|
|
|