Hi guys! I Have a Script here. This script is to be placed to my RPG AI. But I don’t understand
why the AI Just Instantly Follow when i press Play. Any Ideas :)?
SCRIPT:
using UnityEngine;
using System.Collections;
public class EnemyAI : MonoBehaviour
{
public Transform target;
public int minRange;
public bool follow;
public float speed;
public int moveSpeed;
public int rotationSpeed;
private Transform myTransform;
public GameObject enemy;
void Awake()
{
myTransform = transform;
}
void Update ()
{
GameObject go = GameObject.FindGameObjectWithTag("Player");
if(Vector3.Distance(go.transform.position, go.transform.position) < minRange)
target = go.transform;
EnemyHealth eh = (EnemyHealth)enemy.GetComponent("EnemyHealth");
eh.ttarget = target;
follow=true;
if(follow)
{
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);
transform.LookAt(target);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
}
}
LINK HERE ( it was may to long )