Merge pull request #391 from SHADE-DP/AIFixes
Implemented such that AI gets sent to a waypoint of choice (in editor) after capture
This commit is contained in:
commit
ba78f6f7a0
|
@ -4243,6 +4243,7 @@
|
||||||
- Type: Homeowner1
|
- Type: Homeowner1
|
||||||
Enabled: true
|
Enabled: true
|
||||||
waypointsPool: 234
|
waypointsPool: 234
|
||||||
|
startWaypoint: 233
|
||||||
patrolSpeed: 3
|
patrolSpeed: 3
|
||||||
chaseSpeed: 6
|
chaseSpeed: 6
|
||||||
turningSpeed: 5
|
turningSpeed: 5
|
||||||
|
|
|
@ -5912,7 +5912,7 @@
|
||||||
Components: ~
|
Components: ~
|
||||||
Scripts: ~
|
Scripts: ~
|
||||||
- EID: 165
|
- EID: 165
|
||||||
Name: 1
|
Name: 0
|
||||||
IsActive: true
|
IsActive: true
|
||||||
NumberOfChildren: 0
|
NumberOfChildren: 0
|
||||||
Components:
|
Components:
|
||||||
|
@ -5923,7 +5923,7 @@
|
||||||
IsActive: true
|
IsActive: true
|
||||||
Scripts: ~
|
Scripts: ~
|
||||||
- EID: 164
|
- EID: 164
|
||||||
Name: 2
|
Name: 1
|
||||||
IsActive: true
|
IsActive: true
|
||||||
NumberOfChildren: 0
|
NumberOfChildren: 0
|
||||||
Components:
|
Components:
|
||||||
|
@ -5934,7 +5934,7 @@
|
||||||
IsActive: true
|
IsActive: true
|
||||||
Scripts: ~
|
Scripts: ~
|
||||||
- EID: 163
|
- EID: 163
|
||||||
Name: 3
|
Name: 2
|
||||||
IsActive: true
|
IsActive: true
|
||||||
NumberOfChildren: 0
|
NumberOfChildren: 0
|
||||||
Components:
|
Components:
|
||||||
|
@ -5945,7 +5945,7 @@
|
||||||
IsActive: true
|
IsActive: true
|
||||||
Scripts: ~
|
Scripts: ~
|
||||||
- EID: 162
|
- EID: 162
|
||||||
Name: 4
|
Name: 3
|
||||||
IsActive: true
|
IsActive: true
|
||||||
NumberOfChildren: 0
|
NumberOfChildren: 0
|
||||||
Components:
|
Components:
|
||||||
|
@ -5956,7 +5956,7 @@
|
||||||
IsActive: true
|
IsActive: true
|
||||||
Scripts: ~
|
Scripts: ~
|
||||||
- EID: 161
|
- EID: 161
|
||||||
Name: 5
|
Name: 4
|
||||||
IsActive: true
|
IsActive: true
|
||||||
NumberOfChildren: 0
|
NumberOfChildren: 0
|
||||||
Components:
|
Components:
|
||||||
|
@ -5967,7 +5967,7 @@
|
||||||
IsActive: true
|
IsActive: true
|
||||||
Scripts: ~
|
Scripts: ~
|
||||||
- EID: 160
|
- EID: 160
|
||||||
Name: 6
|
Name: 5
|
||||||
IsActive: true
|
IsActive: true
|
||||||
NumberOfChildren: 0
|
NumberOfChildren: 0
|
||||||
Components:
|
Components:
|
||||||
|
@ -5978,7 +5978,7 @@
|
||||||
IsActive: true
|
IsActive: true
|
||||||
Scripts: ~
|
Scripts: ~
|
||||||
- EID: 159
|
- EID: 159
|
||||||
Name: 7
|
Name: 6
|
||||||
IsActive: true
|
IsActive: true
|
||||||
NumberOfChildren: 0
|
NumberOfChildren: 0
|
||||||
Components:
|
Components:
|
||||||
|
@ -5994,7 +5994,7 @@
|
||||||
NumberOfChildren: 0
|
NumberOfChildren: 0
|
||||||
Components:
|
Components:
|
||||||
Transform Component:
|
Transform Component:
|
||||||
Translate: {x: 0.0576689839, y: 0, z: -2.61272359}
|
Translate: {x: -3.45969725, y: 0, z: -2.61272359}
|
||||||
Rotate: {x: -0, y: 0, z: -0}
|
Rotate: {x: -0, y: 0, z: -0}
|
||||||
Scale: {x: 1, y: 1, z: 1}
|
Scale: {x: 1, y: 1, z: 1}
|
||||||
IsActive: true
|
IsActive: true
|
||||||
|
@ -6032,12 +6032,13 @@
|
||||||
- Type: Homeowner1
|
- Type: Homeowner1
|
||||||
Enabled: true
|
Enabled: true
|
||||||
waypointsPool: 166
|
waypointsPool: 166
|
||||||
|
startWaypoint: 162
|
||||||
patrolSpeed: 3
|
patrolSpeed: 3
|
||||||
chaseSpeed: 6
|
chaseSpeed: 6
|
||||||
turningSpeed: 5
|
turningSpeed: 5
|
||||||
sightDistance: 8
|
sightDistance: 8
|
||||||
eyeOffset: [0, 1.64999998, 0]
|
eyeOffset: [0, 1.64999998, 0]
|
||||||
distanceToCapture: 0.5
|
distanceToCapture: 0.800000012
|
||||||
captureTime: 0.5
|
captureTime: 0.5
|
||||||
footstepSFXIntervalMultiplier: 0.5
|
footstepSFXIntervalMultiplier: 0.5
|
||||||
- EID: 12
|
- EID: 12
|
||||||
|
@ -6167,7 +6168,7 @@
|
||||||
Components:
|
Components:
|
||||||
Transform Component:
|
Transform Component:
|
||||||
Translate: {x: 0, y: -300, z: 0}
|
Translate: {x: 0, y: -300, z: 0}
|
||||||
Rotate: {x: -4.5, y: 2, z: -2.5}
|
Rotate: {x: 3.25, y: 0.5, z: 4.5}
|
||||||
Scale: {x: 400, y: 100, z: 500}
|
Scale: {x: 400, y: 100, z: 500}
|
||||||
IsActive: true
|
IsActive: true
|
||||||
Renderable Component:
|
Renderable Component:
|
||||||
|
|
|
@ -37,6 +37,9 @@ public partial class Homeowner1 : BehaviourTree
|
||||||
|
|
||||||
private List<GameObject> waypoints;
|
private List<GameObject> waypoints;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private GameObject startWaypoint;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
[Tooltip("The AI will patrol at this speed")]
|
[Tooltip("The AI will patrol at this speed")]
|
||||||
private float patrolSpeed;
|
private float patrolSpeed;
|
||||||
|
@ -157,6 +160,8 @@ public partial class Homeowner1 : BehaviourTree
|
||||||
SetData("distanceToCapture", distanceToCapture);
|
SetData("distanceToCapture", distanceToCapture);
|
||||||
if (GetData("baseCaptureTime") == null || (float)GetData("baseCaptureTime") != captureTime)
|
if (GetData("baseCaptureTime") == null || (float)GetData("baseCaptureTime") != captureTime)
|
||||||
SetData("baseCaptureTime", captureTime);
|
SetData("baseCaptureTime", captureTime);
|
||||||
|
if (GetData("startWaypoint") == null || (GameObject)GetData("startWaypoint") != startWaypoint)
|
||||||
|
SetData("startWaypoint", startWaypoint);
|
||||||
|
|
||||||
events.Tick();
|
events.Tick();
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
using SHADE;
|
using SHADE;
|
||||||
using SHADE_Scripting.AIBehaviour.BehaviourTree;
|
using SHADE_Scripting.AIBehaviour.BehaviourTree;
|
||||||
|
using SHADE_Scripting.Audio;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -98,6 +99,35 @@ public partial class LeafAttack : BehaviourTreeNode
|
||||||
if (player.GetScript<PlayerController>().stateMachine && !player.GetScript<PlayerController>().stateMachine.IsState(typeof(PlayerCaughtState)))
|
if (player.GetScript<PlayerController>().stateMachine && !player.GetScript<PlayerController>().stateMachine.IsState(typeof(PlayerCaughtState)))
|
||||||
player.GetScript<PlayerController>().stateMachine.SetState(typeof(PlayerCaughtState));
|
player.GetScript<PlayerController>().stateMachine.SetState(typeof(PlayerCaughtState));
|
||||||
|
|
||||||
|
//Teleport AI back to home waypoint
|
||||||
|
int homeIndex = 0;
|
||||||
|
GameObject? startWaypoint = null;
|
||||||
|
List<GameObject>? waypoints = (List<GameObject>)GetNodeData("waypoints");
|
||||||
|
if (GetNodeData("startWaypoint") != null)
|
||||||
|
startWaypoint = (GameObject)GetNodeData("startWaypoint");
|
||||||
|
if (startWaypoint != null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < waypoints.Count; ++i)
|
||||||
|
{
|
||||||
|
if (startWaypoint == waypoints[i])
|
||||||
|
{
|
||||||
|
homeIndex = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SetNodeData("currentWaypointIndex", homeIndex);
|
||||||
|
SetNodeData("playerLastSightedWaypointIndex", homeIndex);
|
||||||
|
SetNodeData("isAlert", false);
|
||||||
|
Audio.SetParameterWithLabel("PlayerDetection", "Undetected");
|
||||||
|
AudioHandler.audioClipHandlers["SFXHumming"].Play();
|
||||||
|
|
||||||
|
Transform? transform = (Transform)GetNodeData("transform");
|
||||||
|
if (waypoints != null && transform != null)
|
||||||
|
{
|
||||||
|
transform.GlobalPosition = waypoints[homeIndex].GetComponent<Transform>().GlobalPosition;
|
||||||
|
}
|
||||||
|
ClearNodeData("target");
|
||||||
|
|
||||||
status = BehaviourTreeNodeStatus.SUCCESS;
|
status = BehaviourTreeNodeStatus.SUCCESS;
|
||||||
onExit(BehaviourTreeNodeStatus.SUCCESS);
|
onExit(BehaviourTreeNodeStatus.SUCCESS);
|
||||||
return status;
|
return status;
|
||||||
|
|
|
@ -60,7 +60,7 @@ public partial class LeafChase : BehaviourTreeNode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Debug.Log("Player is nearest " + nearestWaypointIndex);
|
//Debug.Log("Player is nearest " + nearestWaypointIndex);
|
||||||
//Debug.Log("I'm at " + (int)GetNodeData("currentWaypointIndex"));
|
//Debug.Log("AI going to " + (int)GetNodeData("currentWaypointIndex"));
|
||||||
SetNodeData("playerLastSightedWaypointIndex", nearestWaypointIndex);
|
SetNodeData("playerLastSightedWaypointIndex", nearestWaypointIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,6 +78,7 @@ public partial class LeafChase : BehaviourTreeNode
|
||||||
GetNodeData("distanceToCapture") == null ||
|
GetNodeData("distanceToCapture") == null ||
|
||||||
GetNodeData("baseCaptureTime") == null)
|
GetNodeData("baseCaptureTime") == null)
|
||||||
{
|
{
|
||||||
|
//Debug.Log("Chase Failure: null values");
|
||||||
status = BehaviourTreeNodeStatus.FAILURE;
|
status = BehaviourTreeNodeStatus.FAILURE;
|
||||||
onExit(BehaviourTreeNodeStatus.FAILURE);
|
onExit(BehaviourTreeNodeStatus.FAILURE);
|
||||||
return status;
|
return status;
|
||||||
|
|
|
@ -29,7 +29,7 @@ public partial class LeafPatrol : BehaviourTreeNode
|
||||||
private float chaseSpeed;
|
private float chaseSpeed;
|
||||||
private float turningSpeed;
|
private float turningSpeed;
|
||||||
private float retreatTimer = 0.0f;
|
private float retreatTimer = 0.0f;
|
||||||
private int currentWaypointIndex = 0;
|
private int currentWaypointIndex = -1;
|
||||||
private bool retreatState = false;
|
private bool retreatState = false;
|
||||||
private bool goingForwards = true;
|
private bool goingForwards = true;
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ public partial class LeafPatrol : BehaviourTreeNode
|
||||||
//node, and hence we do not need to inherit its constructors
|
//node, and hence we do not need to inherit its constructors
|
||||||
public LeafPatrol(string name) : base(name)
|
public LeafPatrol(string name) : base(name)
|
||||||
{
|
{
|
||||||
currentWaypointIndex = 0;
|
currentWaypointIndex = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//When it comes to evaluating,
|
//When it comes to evaluating,
|
||||||
|
@ -57,6 +57,42 @@ public partial class LeafPatrol : BehaviourTreeNode
|
||||||
//Debug.LogWarning("LeafPatrol");
|
//Debug.LogWarning("LeafPatrol");
|
||||||
onEnter(BehaviourTreeNodeStatus.RUNNING);
|
onEnter(BehaviourTreeNodeStatus.RUNNING);
|
||||||
|
|
||||||
|
//Initialise home waypoint
|
||||||
|
waypoints = (List<GameObject>)GetNodeData("waypoints");
|
||||||
|
if (currentWaypointIndex == -1)
|
||||||
|
{
|
||||||
|
if (waypoints != null)
|
||||||
|
{
|
||||||
|
//Debug.Log("Waypoints not null");
|
||||||
|
if (GetNodeData("startWaypoint") != null)
|
||||||
|
{
|
||||||
|
//Debug.Log("Getting start waypoint");
|
||||||
|
GameObject startWaypoint = (GameObject)(GetNodeData("startWaypoint"));
|
||||||
|
for (int i = 0; i < waypoints.Count; ++i)
|
||||||
|
{
|
||||||
|
if (startWaypoint == waypoints[i])
|
||||||
|
{
|
||||||
|
//Debug.Log("Leaf Patrol Constructor: Start Waypoint Index: " + i.ToString());
|
||||||
|
currentWaypointIndex = i;
|
||||||
|
SetNodeData("currentWaypointIndex", i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
status = BehaviourTreeNodeStatus.FAILURE;
|
||||||
|
onExit(BehaviourTreeNodeStatus.FAILURE);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
status = BehaviourTreeNodeStatus.FAILURE;
|
||||||
|
onExit(BehaviourTreeNodeStatus.FAILURE);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Get data
|
//Get data
|
||||||
if (GetNodeData("transform") == null ||
|
if (GetNodeData("transform") == null ||
|
||||||
GetNodeData("patrolSpeed") == null ||
|
GetNodeData("patrolSpeed") == null ||
|
||||||
|
@ -104,12 +140,13 @@ public partial class LeafPatrol : BehaviourTreeNode
|
||||||
ClearNodeData("isWaiting");
|
ClearNodeData("isWaiting");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
waypoints = (List<GameObject>)GetNodeData("waypoints");
|
if (GetNodeData("currentWaypointIndex") != null)
|
||||||
if (waypoints == null)
|
|
||||||
{
|
{
|
||||||
return;
|
//2023 Mar 4, 0400, this is needed when the AI teleports back to the first spot after catching
|
||||||
|
currentWaypointIndex = (int)GetNodeData("currentWaypointIndex");
|
||||||
}
|
}
|
||||||
Vector3 targetPosition = waypoints[currentWaypointIndex].GetComponent<Transform>().GlobalPosition;
|
//Modulo operator to prevent out of range exceptions
|
||||||
|
Vector3 targetPosition = waypoints[(currentWaypointIndex % waypoints.Count)].GetComponent<Transform>().GlobalPosition;
|
||||||
//Reach waypoint by X and Z being near enough
|
//Reach waypoint by X and Z being near enough
|
||||||
//Do not consider Y of waypoints yet
|
//Do not consider Y of waypoints yet
|
||||||
Vector3 remainingDistance = targetPosition - transform.GlobalPosition;
|
Vector3 remainingDistance = targetPosition - transform.GlobalPosition;
|
||||||
|
@ -195,6 +232,8 @@ public partial class LeafPatrol : BehaviourTreeNode
|
||||||
//Debug.Log("AI is at " + transform.GlobalPosition.x.ToString() + " " + transform.GlobalPosition.y.ToString() + " " + transform.GlobalPosition.z.ToString());
|
//Debug.Log("AI is at " + transform.GlobalPosition.x.ToString() + " " + transform.GlobalPosition.y.ToString() + " " + transform.GlobalPosition.z.ToString());
|
||||||
Vector3 normalisedDifference = targetPosition - transform.GlobalPosition;
|
Vector3 normalisedDifference = targetPosition - transform.GlobalPosition;
|
||||||
normalisedDifference.y = 0.0f; //Do not move vertically
|
normalisedDifference.y = 0.0f; //Do not move vertically
|
||||||
|
//Debug.Log("Leaf Patrol Current Waypoint Index: " + currentWaypointIndex.ToString());
|
||||||
|
//Debug.Log("True Difference x " + normalisedDifference.x.ToString() + " z " + normalisedDifference.z.ToString());
|
||||||
normalisedDifference /= normalisedDifference.GetMagnitude();
|
normalisedDifference /= normalisedDifference.GetMagnitude();
|
||||||
//Debug.Log("Normalised Difference x " + normalisedDifference.x.ToString() + " z " + normalisedDifference.z.ToString());
|
//Debug.Log("Normalised Difference x " + normalisedDifference.x.ToString() + " z " + normalisedDifference.z.ToString());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue