Hi my script is about enemy " car " following a target . but there is one issue , that when enemy on air , he keeps following the target . I don’t want that . I want him to keep is speed till reaching the ground . How to do this ?
public float speeds;
public bool OnGround;
public float GroundHeight = 0.5f;
void Start () {
}
void Update () {
transform.rotation = Quaternion.Slerp (transform.rotation , Quaternion.LookRotation (target.position - transform.position) , 6 * Time.deltaTime);
Ray FootRay;
RaycastHit hit;
FootRay = new Ray (gameObject.transform.position, Vector3.down);
OnGround = Physics.Raycast (FootRay, out hit, GroundHeight);
if (OnGround == true) {
transform.position += transform.forward * speeds * Time.deltaTime;
}
else {
}
}