Answer the question
In order to leave comments, you need to log in
AI enemy. Enemy behavior, movement animation?
Hello, I'm working on the behavior of mobs, moving them to the sides before attacking, and so on. So far, 3 types of attack, if the player is at a distance of 6 from the enemi, a certain long-range attack, if closer 3 is close, I am writing a 3d game.
How to create an enemi behavior like in souls games for example. For example, I made a banal interval before attacks, a blow and after 2 seconds the enemi just stands or goes then again a blow. But it's kind of gross. And how to connect the animations correctly, it seems to work, what is the problem, the screenshot shows how it is arranged, each animation has a checkmark on has exit time.
code, somewhere not logical I know, but it does not give errors
public Transform povorotPoint;
public float speedrotation;
public GameObject Obj;
//Зона детекта
public string EnemyTag="Player";
public float seeDistance = 7f;//дистанция детекта
private Transform target;
public float attackDistance = 4f;//дистанция атаки
private float timer;//интервал атаки
public GameObject Tochka;
public int name;
// Use this for initialization
void Start () {
target = GameObject.FindWithTag(EnemyTag).transform;
}
// Update is called once per frame
void Update () {
if (Vector3.Distance (transform.position, target.transform.position) < seeDistance) {
Obj.transform.LookAt(povorotPoint);// Быстрый поворот
Obj.GetComponent<Animator> ().SetBool ("Walk", true); //анимация ходьбы
Obj.GetComponent<Animator> ().SetBool ("jumpattack2", true);
}
else
{
Obj.GetComponent<Animator> ().SetBool ("Walk", false); //анимация ходьбы
Obj.GetComponent<Animator> ().SetBool ("jumpattack2", false);
}
if (Vector3.Distance (transform.position, target.transform.position) < attackDistance) {
onAttack ();
Obj.GetComponent<RunOnOf>().enabled = false; // отключение скрипта
}
else
{
Obj.GetComponent<Animator>().SetBool("jumpattack", false);
Obj.GetComponent<Animator>().SetBool("Attack3", false);
Obj.GetComponent<RunOnOf>().enabled = true; // включение скрипта
//Obj.GetComponent<Animator> ().SetBool ("Walk", true); //анимация ходьбы
}
}
void onAttack()
{
timer += 1 * Time.deltaTime;
if (timer >= 2.7f) {
Obj.GetComponent<Animator> ().SetBool ("jumpattack2", false);
name = Random.Range(0,3);
if (name == 1) {
Obj.GetComponent<Animator> ().SetBool ("jumpattack", true); //ближняя атака не проигрывается
} else {
Obj.GetComponent<Animator>().SetBool("Attack3", true); // эта ближняя атака не проигрывается тоже
}
// triggerWeapon.SetActive (true);
timer = 0;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question