mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-10 06:34:16 +00:00
when off nav mesh, if agent is in range of destination, don't move him
This commit is contained in:
parent
565681cd75
commit
eb0ee71ae6
1 changed files with 8 additions and 3 deletions
|
@ -28,11 +28,16 @@ namespace SanAndreasUnity.Utilities
|
|||
if (!m_destinationPosOffNavMesh.HasValue)
|
||||
return this.NavMeshAgent.desiredVelocity;
|
||||
|
||||
// TODO: if we are in range of destination, don't move
|
||||
Vector3 myPosition = this.NavMeshAgent.transform.position;
|
||||
float stoppingDistance = this.StoppingDistance;
|
||||
|
||||
Vector3 diff = m_destinationPosOffNavMesh.Value - this.NavMeshAgent.transform.position;
|
||||
// if we are in range of destination, don't move
|
||||
if (this.Destination.HasValue && Vector3.Distance(this.Destination.Value, myPosition) <= stoppingDistance)
|
||||
return Vector3.zero;
|
||||
|
||||
Vector3 diff = m_destinationPosOffNavMesh.Value - myPosition;
|
||||
float distance = diff.magnitude;
|
||||
if (distance <= this.StoppingDistance)
|
||||
if (distance <= stoppingDistance)
|
||||
return Vector3.zero;
|
||||
return diff / distance;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue