I've got an enemy coded for a project I'm working on. The enemy is supposed to look at and follow the player once they get within a certain distance. The problem is, recently we've started using a new program to move the player throughout the level. The issue is, this program moves the player without actually changing the transform component of the object and I don't know how to alter my code to deal with that.
Here's the target assignment, the follow method and the lines that assign the distance from the player as well as the calls for the LookAt and Follow methods.
void Start (){
Target = GameObject.FindGameObjectWithTag ("Player").transform;
}
void Update () {
Distance = Vector3.Distance (Target.position + Target.transform.forward, transform.position);
if (Distance < LookAtDistance)
{
LookAt();
}
if (Distance > MinDistance && Distance <= MaxDistance && parenting == false)
{
follow ();
}
void follow(){
transform.Translate(Vector3.forward * MoveSpeed * Time.deltaTime);
}
Any help would be greatly appreciated.
↧