From ecd1efee5642c42b29317107b77ad4a54d4ceb04 Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Thu, 3 Nov 2022 21:25:43 +0800 Subject: [PATCH] AI Capture Mechanic --- TempScriptsFolder/AIPrototype.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/TempScriptsFolder/AIPrototype.cs b/TempScriptsFolder/AIPrototype.cs index 80fa643e..d678de78 100644 --- a/TempScriptsFolder/AIPrototype.cs +++ b/TempScriptsFolder/AIPrototype.cs @@ -25,15 +25,19 @@ public class AIPrototype : Script [SerializeField] [Tooltip("How fast the object moves about waypoints")] - private float patrolSpeed = 1.0f; + private float patrolSpeed = 0.4f; [SerializeField] [Tooltip("How fast the object moves while chasing")] - private float chaseSpeed = 1.5f; + private float chaseSpeed = 0.8f; + + [SerializeField] + [Tooltip("How near the player must be to the AI for capture")] + private float distanceToCapture = 1.2f; [SerializeField] [Tooltip("How near the player must be for the chase to begin. Should be less than distanceToEndChase")] - private float distanceToStartChase = 1.5f; + private float distanceToStartChase = 2.0f; [SerializeField] [Tooltip("How far the player must be for the chase to end. Should be greater than distanceToStartChase")] @@ -151,6 +155,12 @@ public class AIPrototype : Script //TODO delete this when original intended code above works with velocity being limited correctly rb.LinearVelocity = normalisedDifference * chaseSpeed; + //Capture player if near enough + if ((pTransform.GlobalPosition - transform.GlobalPosition).GetMagnitude() <= distanceToCapture) + { + player.GetValueOrDefault().GetScript().currentState = PlayerController.RaccoonStates.CAUGHT; + } + //End chase if too far if ((pTransform.GlobalPosition - transform.GlobalPosition).GetMagnitude() >= distanceToEndChase) {