mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-10 06:34:16 +00:00
properly stopping if close enough to destination
This commit is contained in:
parent
ef053b9c45
commit
2fb543ef0a
2 changed files with 11 additions and 12 deletions
|
@ -20,6 +20,8 @@ namespace SanAndreasUnity.Behaviours
|
|||
|
||||
public Vector3? NextMovementPos { get; private set; } = null;
|
||||
|
||||
public Vector3 GetDesiredVelocity(NavMeshAgent agent) => agent.desiredVelocity;
|
||||
|
||||
|
||||
|
||||
public void Update(NavMeshAgent agent)
|
||||
|
|
|
@ -220,24 +220,21 @@ namespace SanAndreasUnity.Behaviours.Peds.AI
|
|||
if (this.MyPed.IsInVehicle)
|
||||
return;
|
||||
|
||||
_ped.MovementAgent.Destination = targetPos;
|
||||
|
||||
/*Vector3? nextMovementPos = _movementAgent.NextMovementPos;
|
||||
if (!nextMovementPos.HasValue)
|
||||
float distance = (_ped.transform.position - targetPos).magnitude;
|
||||
if (distance <= currentStoppingDistance)
|
||||
return;
|
||||
|
||||
Vector3 diff = nextMovementPos.Value - _ped.transform.position;
|
||||
*/
|
||||
Vector3 diff = _ped.NavMeshAgent.desiredVelocity.WithXAndZ();
|
||||
float distance = diff.magnitude;
|
||||
_ped.MovementAgent.Destination = targetPos;
|
||||
|
||||
if (distance > 0.001f)
|
||||
Vector3 desiredVelocity = _ped.MovementAgent.GetDesiredVelocity(_ped.NavMeshAgent).WithXAndZ();
|
||||
|
||||
if (desiredVelocity != Vector3.zero)
|
||||
{
|
||||
Vector3 diffDir = diff.normalized;
|
||||
Vector3 moveInput = desiredVelocity.normalized;
|
||||
|
||||
this.MyPed.IsRunOn = true;
|
||||
this.MyPed.Movement = diffDir;
|
||||
this.MyPed.Heading = diffDir;
|
||||
this.MyPed.Movement = moveInput;
|
||||
this.MyPed.Heading = moveInput;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue