mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-22 20:13:02 +00:00
escape state done
This commit is contained in:
parent
b673942f1e
commit
8adfc87913
4 changed files with 51 additions and 26 deletions
28
Assets/Scripts/Behaviours/PedAI/EscapeState.cs
Normal file
28
Assets/Scripts/Behaviours/PedAI/EscapeState.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace SanAndreasUnity.Behaviours.Peds.AI
|
||||
{
|
||||
public class EscapeState : BaseState
|
||||
{
|
||||
private readonly PathMovementData _pathMovementData = new PathMovementData();
|
||||
|
||||
|
||||
public override void UpdateState()
|
||||
{
|
||||
// TODO: exit vehicle
|
||||
|
||||
if (PedAI.ArrivedAtDestinationNode(_pathMovementData, _ped.transform))
|
||||
PedAI.OnArrivedToDestinationNode(_pathMovementData);
|
||||
|
||||
if (!_pathMovementData.destinationNode.HasValue)
|
||||
{
|
||||
PedAI.FindClosestWalkableNode(_pathMovementData, _ped.transform.position);
|
||||
return;
|
||||
}
|
||||
|
||||
this.MyPed.IsSprintOn = true;
|
||||
this.MyPed.Movement = (_pathMovementData.moveDestination - this.MyPed.transform.position).normalized;
|
||||
this.MyPed.Heading = this.MyPed.Movement;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Behaviours/PedAI/EscapeState.cs.meta
Normal file
11
Assets/Scripts/Behaviours/PedAI/EscapeState.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 338dada8543a5844a874473543f40680
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -290,22 +290,19 @@ namespace SanAndreasUnity.Behaviours.Peds.AI
|
|||
return targetNode.Position + offset.ToVector3XZ();
|
||||
}
|
||||
|
||||
void UpdateEscaping()
|
||||
public static void FindClosestWalkableNode(PathMovementData pathMovementData, Vector3 position)
|
||||
{
|
||||
// TODO: exit vehicle
|
||||
|
||||
if (this.ArrivedAtDestinationNode())
|
||||
this.OnArrivedToDestinationNode();
|
||||
|
||||
if (!this.HasTargetNode)
|
||||
{
|
||||
this.FindNextNodeDelayed();
|
||||
if (Time.time - pathMovementData.timeWhenAttemptedToFindClosestNode < 2f) // don't attempt to find it every frame
|
||||
return;
|
||||
}
|
||||
|
||||
this.MyPed.IsSprintOn = true;
|
||||
this.MyPed.Movement = (_moveDestination - this.MyPed.transform.position).normalized;
|
||||
this.MyPed.Heading = this.MyPed.Movement;
|
||||
pathMovementData.timeWhenAttemptedToFindClosestNode = Time.time;
|
||||
|
||||
var closestPathNodeToWalk = PedAI.GetClosestPathNodeToWalk(position);
|
||||
if (null == closestPathNodeToWalk)
|
||||
return;
|
||||
|
||||
pathMovementData.destinationNode = closestPathNodeToWalk;
|
||||
pathMovementData.moveDestination = PedAI.GetMoveDestinationBasedOnTargetNode(closestPathNodeToWalk.Value);
|
||||
}
|
||||
|
||||
void UpdateFollowing()
|
||||
|
|
|
@ -9,12 +9,12 @@ namespace SanAndreasUnity.Behaviours.Peds.AI
|
|||
public PathNode? currentNode;
|
||||
public PathNode? destinationNode;
|
||||
public Vector3 moveDestination;
|
||||
public float timeWhenAttemptedToFindClosestNode = 0f;
|
||||
}
|
||||
|
||||
public class WalkAroundState : BaseState
|
||||
{
|
||||
private readonly PathMovementData _pathMovementData = new PathMovementData();
|
||||
private float _timeWhenAttemptedToFindClosestNode = 0f;
|
||||
|
||||
|
||||
public override void UpdateState()
|
||||
|
@ -42,18 +42,7 @@ namespace SanAndreasUnity.Behaviours.Peds.AI
|
|||
|
||||
if (!_pathMovementData.destinationNode.HasValue)
|
||||
{
|
||||
if (Time.time - _timeWhenAttemptedToFindClosestNode > 2f) // don't attempt to find it every frame
|
||||
{
|
||||
_timeWhenAttemptedToFindClosestNode = Time.time;
|
||||
|
||||
var closestPathNodeToWalk = PedAI.GetClosestPathNodeToWalk(_ped.transform.position);
|
||||
if (null == closestPathNodeToWalk)
|
||||
return;
|
||||
|
||||
_pathMovementData.destinationNode = closestPathNodeToWalk;
|
||||
_pathMovementData.moveDestination = PedAI.GetMoveDestinationBasedOnTargetNode(closestPathNodeToWalk.Value);
|
||||
}
|
||||
|
||||
PedAI.FindClosestWalkableNode(_pathMovementData, _ped.transform.position);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue