Hi, I am really new at doing this and I have decided to make a game just to learn what I am doing. I am making my enemy wander around then attack the player when they get to a certain distance. When the player gets to the distance needed for the enemy to attack the enemy just runs up into the air. I don’t know if I am in the right forums but I came here because I believe this script is causing it. Thank you.
2185260–144895–AISimple.js (920 Bytes)
Please use code tags:
var target : Transform;
var moveSpeed = 0;
var rotationSpeed = 3;
var player : Transform;
var distance:float = 5.8;
var distanceAttack:float = 2.6;
var myTransform : Transform;
function Awake() {
myTransform = transform;
}
function Start() {
target = GameObject.FindWithTag("Player").transform;
}
function Update () {
if(Vector3.Distance(transform.position, player.position) < distance){
if(Vector3.Distance(transform.position, player.position) >distanceAttack){
moveSpeed = 2;
animation.Play("walk");
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
if(Vector3.Distance(transform.position, player.position) < distanceAttack){
moveSpeed = 0;
animation.Play("bite");
}
}
else{
moveSpeed = 0;
}
}
Could you provide a animated gif or video of what is happening while your enemy tries to attack. Is your “bite” animation build the same way as your walk animation? Could you try to change the moveSpeed to something small when attacking, so we see, if it is happening on your moveSpeed = 0.