fix: enemies snapping to the incorrect position if they had a path and trying to use the path if they were aggro'd to an enemy (#2005)

* fix: enemies snapping to the incorrect position if they had a path

tested that ags enemies no longer snap backwards a large amount

* fix: move the home point so we can aggro correctly
This commit is contained in:
David Markowitz
2026-06-19 02:12:47 -07:00
committed by GitHub
parent 56504d9447
commit 308412f46e

View File

@@ -37,8 +37,6 @@ MovementAIComponent::MovementAIComponent(Entity* parent, const int32_t component
m_Info = info; m_Info = info;
m_AtFinalWaypoint = true; m_AtFinalWaypoint = true;
m_BaseCombatAI = nullptr;
m_BaseCombatAI = m_Parent->GetComponent<BaseCombatAIComponent>(); m_BaseCombatAI = m_Parent->GetComponent<BaseCombatAIComponent>();
//Try and fix the insane values: //Try and fix the insane values:
@@ -131,7 +129,11 @@ void MovementAIComponent::Update(const float deltaTime) {
m_TimeTravelled += deltaTime; m_TimeTravelled += deltaTime;
SetPosition(ApproximateLocation()); const auto approxPos = ApproximateLocation();
SetPosition(approxPos);
// Set the AIs new home based on where our current waypoint is IF we're idle, that way we can return to this
// when resuming the pathing after losing aggro while moving the aggro hitbox with us
if (m_BaseCombatAI && m_BaseCombatAI->GetState() == AiState::idle) m_BaseCombatAI->SetStartingPosition(approxPos);
if (m_TimeTravelled < m_TimeToTravel) return; if (m_TimeTravelled < m_TimeToTravel) return;
m_TimeTravelled = 0.0f; m_TimeTravelled = 0.0f;
@@ -166,6 +168,8 @@ void MovementAIComponent::Update(const float deltaTime) {
SetRotation(QuatUtils::LookAt(source, m_NextWaypoint)); SetRotation(QuatUtils::LookAt(source, m_NextWaypoint));
} }
} else { } else {
// Only try to renew or continue the path if we're in the idle or spawn state and we actually have a combatAI component
if (!m_BaseCombatAI || (m_BaseCombatAI && m_BaseCombatAI->GetState() == AiState::idle)) {
// Check if there are more waypoints in the queue, if so set our next destination to the next waypoint // Check if there are more waypoints in the queue, if so set our next destination to the next waypoint
const auto waypointNum = m_IsBounced ? m_CurrentPath.size() : m_CurrentPathWaypointCount - m_CurrentPath.size() - 1; const auto waypointNum = m_IsBounced ? m_CurrentPath.size() : m_CurrentPathWaypointCount - m_CurrentPath.size() - 1;
RunWaypointCommands(waypointNum); RunWaypointCommands(waypointNum);
@@ -180,7 +184,6 @@ void MovementAIComponent::Update(const float deltaTime) {
SetPath(waypoints); SetPath(waypoints);
} else if (m_Path->pathBehavior == PathBehavior::Once) { } else if (m_Path->pathBehavior == PathBehavior::Once) {
// In this case we intended to follow a path and once we've followed it we camp there, otherwise we'd just wander home again. // In this case we intended to follow a path and once we've followed it we camp there, otherwise we'd just wander home again.
if (m_BaseCombatAI) m_BaseCombatAI->SetStartingPosition(m_SourcePosition);
Stop(); Stop();
return; return;
} }
@@ -194,6 +197,7 @@ void MovementAIComponent::Update(const float deltaTime) {
m_CurrentPath.pop(); m_CurrentPath.pop();
} }
} }
}
Game::entityManager->SerializeEntity(m_Parent); Game::entityManager->SerializeEntity(m_Parent);
} }
@@ -218,8 +222,7 @@ NiPoint3 MovementAIComponent::GetCurrentWaypoint() const {
NiPoint3 MovementAIComponent::ApproximateLocation() const { NiPoint3 MovementAIComponent::ApproximateLocation() const {
auto source = m_SourcePosition; auto source = m_SourcePosition;
if (AtFinalWaypoint()) return m_Parent->GetPosition();
if (AtFinalWaypoint()) return source;
auto destination = m_NextWaypoint; auto destination = m_NextWaypoint;
@@ -521,6 +524,7 @@ bool MovementAIComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInf
movementInfo.PushDebug<AMFBoolValue>("Lock Rotation") = m_LockRotation; movementInfo.PushDebug<AMFBoolValue>("Lock Rotation") = m_LockRotation;
movementInfo.PushDebug<AMFBoolValue>("Paused") = m_Paused; movementInfo.PushDebug<AMFBoolValue>("Paused") = m_Paused;
movementInfo.PushDebug<AMFDoubleValue>("Pulling To Point") = m_PullingToPoint; movementInfo.PushDebug<AMFDoubleValue>("Pulling To Point") = m_PullingToPoint;
movementInfo.PushDebug<AMFBoolValue>("At Final Waypoint") = m_AtFinalWaypoint;
auto& pullPointInfo = movementInfo.PushDebug("Pull Point"); auto& pullPointInfo = movementInfo.PushDebug("Pull Point");
pullPointInfo.PushDebug<AMFDoubleValue>("X") = m_PullPoint.x; pullPointInfo.PushDebug<AMFDoubleValue>("X") = m_PullPoint.x;