mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-10 06:34:16 +00:00
use "stopping distance" from NavMeshAgent, don't try to manually stop him
This commit is contained in:
parent
b8300b25ec
commit
3124685f47
2 changed files with 21 additions and 9 deletions
|
@ -224,12 +224,7 @@ namespace SanAndreasUnity.Behaviours.Peds.AI
|
|||
}
|
||||
|
||||
_ped.MovementAgent.Destination = targetPos;
|
||||
|
||||
Vector3? calculatedDestination = _ped.MovementAgent.CalculatedDestination;
|
||||
Vector3 targetPosToCalculateDistance = ignoreCalculatedDestination ? targetPos : calculatedDestination.GetValueOrDefault(targetPos);
|
||||
float distance = (_ped.transform.position - targetPosToCalculateDistance).magnitude;
|
||||
if (distance <= currentStoppingDistance)
|
||||
return;
|
||||
_ped.MovementAgent.StoppingDistance = currentStoppingDistance;
|
||||
|
||||
Vector3 desiredVelocity = _ped.MovementAgent.DesiredVelocity.WithXAndZ();
|
||||
|
||||
|
|
|
@ -21,14 +21,31 @@ namespace SanAndreasUnity.Utilities
|
|||
private float m_lastTimeWhenWarped = 0f;
|
||||
private float m_timeSinceSampledOffNavMesh = 0f;
|
||||
|
||||
public Vector3 DesiredVelocity => m_sampledPosOffNavMesh.HasValue
|
||||
? (m_sampledPosOffNavMesh.Value - this.NavMeshAgent.transform.position).normalized
|
||||
: this.NavMeshAgent.desiredVelocity;
|
||||
public Vector3 DesiredVelocity
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!m_sampledPosOffNavMesh.HasValue)
|
||||
return this.NavMeshAgent.desiredVelocity;
|
||||
|
||||
Vector3 diff = m_sampledPosOffNavMesh.Value - this.NavMeshAgent.transform.position;
|
||||
float distance = diff.magnitude;
|
||||
if (distance <= this.StoppingDistance)
|
||||
return Vector3.zero;
|
||||
return diff / distance;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3? CalculatedDestination { get; private set; } = null;
|
||||
|
||||
private Vector3? m_sampledPosOffNavMesh = null;
|
||||
|
||||
public float StoppingDistance
|
||||
{
|
||||
get => this.NavMeshAgent.stoppingDistance;
|
||||
set => this.NavMeshAgent.stoppingDistance = value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Awake()
|
||||
|
|
Loading…
Reference in a new issue