Merge pull request #169 from SHADE-DP/ScriptingAI

AI Capture Mechanic
AI will set player's state to 'CAUGHT' if close enough. This threshold distance can be set in the editor.
This commit is contained in:
XiaoQiDigipen 2022-11-04 10:34:50 +08:00 committed by GitHub
commit 74b9882024
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 3 deletions

View File

@ -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<PlayerController>().currentState = PlayerController.RaccoonStates.CAUGHT;
}
//End chase if too far
if ((pTransform.GlobalPosition - transform.GlobalPosition).GetMagnitude() >= distanceToEndChase)
{