Hey guys I have this AI script that’s not behaving correctly when I placed it on a soldier model it works fine when I place it on another model but not the soldier, even thou on the soldier model it plays the animations it wont move the soldier transform when not near the player and it continuously plays the WalkFire animation when its not near the player, moving in place but not going anywhere do anyone have any thoughts or suggestions for this matter
using UnityEngine;
using System.Collections;
public class enemyAi : MonoBehaviour {
public float speed = .05f;
public Transform eneModel;
public string[] animationNames;
private float _hMove;
private float _yMove;
private RaycastHit _h;
private Transform _Player;
private float _distanceFromPlayer;
// Use this for initialization
void Start () {
_Player = GameObject.FindGameObjectWithTag("Player").transform;
}
// Update is called once per frame
void Update () {
_distanceFromPlayer = Vector3.Distance(transform.position, _Player.position);
if(_distanceFromPlayer <= 1.0){
if(Physics.Raycast(transform.position, transform.forward, out _h))
eneModel.animation.Play(animationNames[Random.Range(0, animationNames.Length - 1)]);
}
else
if(_distanceFromPlayer <= 4.0){
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(_Player.position - transform.position), Time.deltaTime * 4);
transform.Translate(0, 0, .11f);
eneModel.animation.CrossFade("WalkFire");
}else{
//transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(_Player.position - transform.position), Time.deltaTime * 4);
transform.Translate(0, 0, .1f);
eneModel.animation.CrossFade("Walk");
}
}
}