Hello, I made some kind of script where my zombie chases me and makes it with animations(even tho its not really working- also set the parameters correctly)…but my main problem is that when I enter 60 degrees within zombies sight he just like comes super fast which I want him to do slowly and closer(if I get a little away he follows me)
using UnityEngine;
using System.Collections;
public class chases : MonoBehaviour {
public Transform player;
public Transform head;
static Animator anim;
bool pursuing = false;
public float speed = 0.1f;
// Use this for initialization
void Start ()
{
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update ()
{
Vector3 direction = player.position - this.transform.position;
direction.y = 0 * speed;
float angle = Vector3.Angle(direction, head.up);
if(Vector3.Distance(player.position, this.transform.position) < 10 && (angle < 60 || pursuing)) //ako je u distanci od 10 i pod kutem od 60
{
pursuing = true;
this.transform.rotation = Quaternion.Slerp(this.transform.rotation,
Quaternion.LookRotation(direction), 0.1f);
anim.SetBool("isIdle",false);
if(direction.magnitude > 5)
{
this.transform.Translate(0,0,0.05f);
anim.SetBool("isWalking",true);
anim.SetBool("isAttacking",false);
}
else
{
anim.SetBool("isAttacking",true);
anim.SetBool("isWalking",false);
}
}
else
{
anim.SetBool("isIdle", true);
anim.SetBool("isWalking", false);
anim.SetBool("isAttacking", false);
pursuing = false;
}
}
}