From 154db088c298bf4a3b328166af0e059e576d21fb Mon Sep 17 00:00:00 2001 From: Benjamin Comeau Date: Sat, 7 Nov 2015 15:28:15 -0500 Subject: [PATCH] bug fix --- Assets/Scripts/monsterAI.cs | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/Assets/Scripts/monsterAI.cs b/Assets/Scripts/monsterAI.cs index f114c40..0b37fed 100644 --- a/Assets/Scripts/monsterAI.cs +++ b/Assets/Scripts/monsterAI.cs @@ -4,37 +4,47 @@ using System.Collections; public class monsterAI : MonoBehaviour { public GameObject player; - private Transform target = player.transform; + private Transform target; public float deadlyDistance; - public float rotationDamping; + public float rotationDamping; // Lower rotation damping = slower rotation + public float moveSpeed; // Use this for initialization void Start () { + target = player.transform; } // Update is called once per frame void Update () { + if (IsAtDeadlyDistance ()) { + // Kill the player + } else { + LookAtTarget (); + MoveTowardTarget (); + } } // Check is the current distance is deadly for the target - bool IsAtDeadlyDistance () { - return (deadlyDistance <= Vector3.Distance(target.position, transform.position); - } - - // Follow player from a certain initial distance at a certain speed. - void FollowTarget () + bool IsAtDeadlyDistance () { - + return (deadlyDistance <= Vector3.Distance (target.position, transform.position)); } // Look toward target - void LookAtTarget () { - Quaternion rotation = Quaternion.LookRotation (target.rotation - transform.rotation); - transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * rotationDamping); + void LookAtTarget () + { + //Quaternion rotation = Quaternion.LookRotation (target.rotation - transform.rotation); + //transform.rotation = Quaternion.Slerp (transform.rotation, rotation, Time.deltaTime * rotationDamping); } + // Follow player from a certain initial distance at a certain speed. + void MoveTowardTarget () + { + transform.Translate (Vector3.forward * moveSpeed * Time.deltaTime); + } + }