when off nav mesh, if agent is in range of destination, don't move him

This commit is contained in:
in0finite 2022-03-21 00:10:36 +01:00
parent 565681cd75
commit eb0ee71ae6

View file

@ -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;
}