if(target.isEmpty()||!target.getRefData().getCount()||!target.getRefData().isEnabled()// Really we should be checking whether the target is currently registered
// with the MechanicsManager
)
returnfalse;// Target is not here right now, wait for it to return
// Target is not here right now, wait for it to return
// Really we should be checking whether the target is currently registered with the MechanicsManager
storage.mMoving=!pathTo(actor,dest,duration,baseFollowDistance);// Go to the destination
storage.mMoving=!pathTo(actor,targetPos,duration,baseFollowDistance);// Go to the destination
if(storage.mMoving)
{
//Check if you're far away
floatdist=distance(dest,pos.asVec3());
if(dist>450)
if(targetDir.length2()>450*450)
actor.getClass().getCreatureStats(actor).setMovementFlag(MWMechanics::CreatureStats::Flag_Run,true);//Make NPC run
elseif(dist <325)//Have a bit of a dead zone, otherwise npc will constantly flip between running and not when right on the edge of the running threshold
elseif(targetDir.length2()<325*325)//Have a bit of a dead zone, otherwise npc will constantly flip between running and not when right on the edge of the running threshold
actor.getClass().getCreatureStats(actor).setMovementFlag(MWMechanics::CreatureStats::Flag_Run,false);//make NPC walk
constMWWorld::Ptrtarget=MWBase::Environment::get().getWorld()->searchPtrViaActorId(mTargetActorId);//The target to follow
if(target==MWWorld::Ptr()||!target.getRefData().getCount()||!target.getRefData().isEnabled()// Really we should be checking whether the target is currently registered
// with the MechanicsManager
)
returntrue;//Target doesn't exist
// Stop if the target doesn't exist
// Really we should be checking whether the target is currently registered with the MechanicsManager
// Maximum travel distance for vanilla compatibility.
// Was likely meant to prevent NPCs walking into non-loaded exterior cells, but for some reason is used in interior cells as well.
// We can make this configurable at some point, but the default *must* be the below value. Anything else will break shoddily-written content (*cough* MW *cough*) in bizarre ways.
// The specific range below is configurable, but its limit is currently 7168 units. Anything greater will break shoddily-written content (*cough* MW *cough*) in bizarre ways.
constosg::Vec3fplayerHalfExtents=MWBase::Environment::get().getWorld()->getHalfExtents(getPlayer());// Using player half extents for better performance