[Follow] If target av isn't rendered, still try to get their position

Mainly moves code around, rather small change.
This commit is contained in:
Liru Færs
2020-01-08 13:15:37 -05:00
parent 094c948a87
commit a21927e510

View File

@@ -1757,16 +1757,25 @@ void LLAgent::autoPilot(F32 *delta_yaw)
bool follow = !mLeaderID.isNull(); //mAutoPilotBehaviorName == "Follow";
if (follow)
{
LLViewerObject* object = gObjectList.findObject(mLeaderID);
if (!object)
if (auto object = gObjectList.findObject(mLeaderID))
{
mAutoPilotBehaviorName.clear(); // Nothing left to follow pilot
stopAutoPilot();
return;
mAutoPilotTargetGlobal = object->getPositionGlobal();
if (const auto& av = object->asAvatar()) // Fly if avatar target is flying
setFlying(av->mInAir);
}
else // We might still have a valid avatar pos
{
const LLVector3d& get_av_pos(const LLUUID & id);
auto pos = get_av_pos(mLeaderID);
if (pos.isExactlyZero()) // Default constructed or invalid from server
{
mAutoPilotBehaviorName.clear(); // Nothing left to follow pilot
stopAutoPilot();
return;
}
mAutoPilotTargetGlobal = pos;
// Should we fly if the height difference is great enough here? Altitude is often invalid...
}
mAutoPilotTargetGlobal = object->getPositionGlobal();
if (const auto& av = object->asAvatar()) // Fly if avatar target is flying
setFlying(av->mInAir);
}
if (!isAgentAvatarValid()) return;