mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-10 06:34:16 +00:00
handle cases when destination changes by significant amount, but it's not recognized by "delta position" method
This commit is contained in:
parent
e35f238e55
commit
bc26a10ab5
1 changed files with 16 additions and 2 deletions
|
@ -71,6 +71,8 @@ namespace SanAndreasUnity.Utilities
|
|||
|
||||
NavMeshAgent agent = this.NavMeshAgent;
|
||||
|
||||
// TODO: handle case when Agent is disabled
|
||||
|
||||
Vector3 myPosition = agent.transform.position;
|
||||
|
||||
agent.nextPosition = myPosition;
|
||||
|
@ -95,7 +97,7 @@ namespace SanAndreasUnity.Utilities
|
|||
}
|
||||
}
|
||||
|
||||
Debug.Log($"warped agent {agent.name} - bWarp {bWarp}, isOnNavMesh {agent.isOnNavMesh}, pos diff {retreivedNextPosition - myPosition}, bSetDestination {bSetDestination}", this);
|
||||
//Debug.Log($"warped agent {agent.name} - bWarp {bWarp}, isOnNavMesh {agent.isOnNavMesh}, pos diff {retreivedNextPosition - myPosition}, bSetDestination {bSetDestination}", this);
|
||||
}
|
||||
|
||||
// no need to set velocity, it's automatically set by Agent
|
||||
|
@ -118,7 +120,7 @@ namespace SanAndreasUnity.Utilities
|
|||
if (NavMesh.SamplePosition(myPosition, out var hit, 150f, agent.areaMask))
|
||||
m_sampledPosOffNavMesh = hit.position;
|
||||
|
||||
Debug.Log($"Tried to sample position off nav mesh - agent {agent.name}, sampled pos {m_sampledPosOffNavMesh}, distance {hit.distance}", this);
|
||||
//Debug.Log($"Tried to sample position off nav mesh - agent {agent.name}, sampled pos {m_sampledPosOffNavMesh}, distance {hit.distance}", this);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -195,6 +197,18 @@ namespace SanAndreasUnity.Utilities
|
|||
return;
|
||||
}
|
||||
|
||||
// handle cases when destination changes by significant amount, but it's not recognized
|
||||
// by "delta position" method above
|
||||
|
||||
float deltaInPosition = (this.Destination.Value - m_lastAssignedDestination.Value).magnitude;
|
||||
float currentDistance = (m_lastAssignedDestination.Value - myPosition).magnitude;
|
||||
if (deltaInPosition > currentDistance)
|
||||
{
|
||||
Debug.Log($"delta pos higher than current distance - agent {agent.name}, delta {deltaInPosition}, current distance {currentDistance}", this);
|
||||
this.SetDestination();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SetDestination()
|
||||
|
|
Loading…
Reference in a new issue