My enemy ai won't stay on the ground help please
I am having a problem with my enemy ai . Whenever I click on play the enemy ai go in the air move toward the player ' when the player is in distance. I also have some animations attach to the enemy ai and I have all of them on loop . I think their is something wrong with my code . I just want the enemy to stay on the ground and the animations to play. Here is my C # script. Help would be appreciated.
using UnityEngine; using System.Collections;
public class an : MonoBehaviour { //nav mesh agent needed public Transform target; public float Distance; public float rotationdamping; public float moveSpeed ;
void Start () {
}
void Update () {
Distance = Vector3.Distance (target.position, transform.position);
if (Distance < 4f)
{
watchplayer();
}
if(Distance < 3f)
{
if(Distance > 2f)
{
follow();
}
else if(Distance < 2f)
{
attackmode();
}
}
}
void watchplayer()
{
Quaternion rotation = Quaternion.LookRotation (target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * rotationdamping);
GetComponent<Animation>().Play("idle");
}
void follow()
{
transform.Translate(moveSpeed * Vector3.forward * Time.deltaTime);
GetComponent<Animation>().Play("move");
}
void attackmode()
{
GetComponent<Animation>().Play("attack");
}
}
Comment