Added SFX to AI

- Footsteps, alert yell and unalert humming
This commit is contained in:
mushgunAX 2022-11-25 00:56:40 +08:00
parent d6fab4439f
commit 4daaa8e897
3 changed files with 17 additions and 22 deletions

View File

@ -103,7 +103,7 @@ public partial class Homeowner1 : BehaviourTree
footstepTimeRemaining -= velocity * Time.DeltaTimeF;
if (footstepTimeRemaining < 0.0f)
{
Debug.Log("AI Play Footstep SFX");
Audio.PlaySFXOnce2D("event:/Homeowner/homeowner_footsteps");
footstepTimeRemaining = footstepSFXIntervalMultiplier;
}
}

View File

@ -71,7 +71,7 @@ public partial class LeafChase : BehaviourTreeNode
if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == true)
{
Debug.Log("AI play unalert hmm");
Audio.PlaySFXOnce2D("event:/Homeowner/humming");
}
SetNodeData("isAlert", false);

View File

@ -41,7 +41,6 @@ public partial class LeafSearch : BehaviourTreeNode
//Helper, find the nearest unobstructed waypoint to return to when chase is over
private void reevaluateWaypoint()
{
Debug.Log("Reevaluating Waypoints");
List<GameObject> waypoints = (List<GameObject>)GetNodeData("waypoints");
if (waypoints == null)
@ -62,6 +61,17 @@ public partial class LeafSearch : BehaviourTreeNode
SetNodeData("currentWaypointIndex", nearestWaypointIndex);
}
//Helper for handling stopping of chases
private void handleChaseStop()
{
if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == true)
{
Audio.PlaySFXOnce2D("event:/Homeowner/humming");
reevaluateWaypoint();
}
SetNodeData("isAlert", false);
}
public override BehaviourTreeNodeStatus Evaluate()
{
//Debug.LogWarning("LeafSearch");
@ -94,12 +104,7 @@ public partial class LeafSearch : BehaviourTreeNode
if ((plrT.GlobalPosition - transform.GlobalPosition).GetMagnitude() > sightDistance)
{
//Debug.Log("Failure: Too far");
if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == true)
{
Debug.Log("AI play unalert hmm");
reevaluateWaypoint();
}
SetNodeData("isAlert", false);
handleChaseStop();
status = BehaviourTreeNodeStatus.FAILURE;
onExit(BehaviourTreeNodeStatus.FAILURE);
return status;
@ -114,12 +119,7 @@ public partial class LeafSearch : BehaviourTreeNode
if (Vector3.Dot(difference, lookDirection) < 0.0f)
{
//Debug.Log("Failure: Out of FOV");
if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == true)
{
Debug.Log("AI play unalert hmm");
reevaluateWaypoint();
}
SetNodeData("isAlert", false);
handleChaseStop();
status = BehaviourTreeNodeStatus.FAILURE;
onExit(BehaviourTreeNodeStatus.FAILURE);
return status;
@ -140,12 +140,7 @@ public partial class LeafSearch : BehaviourTreeNode
if (sightRayHit.Hit && sightRayHit.Other != player)
{
//Debug.Log("Failure: Ray hit obstacle named " + sightRayHit.Other.GetValueOrDefault().Name + " ID" + sightRayHit.Other.GetValueOrDefault().EntityId);
if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == true)
{
Debug.Log("AI play unalert hmm");
reevaluateWaypoint();
}
SetNodeData("isAlert", false);
handleChaseStop();
status = BehaviourTreeNodeStatus.FAILURE;
onExit(BehaviourTreeNodeStatus.FAILURE);
return status;
@ -162,7 +157,7 @@ public partial class LeafSearch : BehaviourTreeNode
if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == false)
{
Debug.Log("AI Play Alerted Yell here");
Audio.PlaySFXOnce2D("event:/Homeowner/homeowner_detect_raccoon");
}
SetNodeData("isAlert", true);