Hello guys i made a enemy with enemy script and animator(with bools). It’s working perfect but i have 2 problems. He can attack a player of different height. Here is the screenshot of the “problem”
And as you can see that enemy is attacking from different height. And 2nd problem is that he is floating. he have rigidbody how can i stop him from floating…
Also here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyChase : MonoBehaviour {
public Transform player;
static Animator anim;
void Start () {
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update () {
if (Vector3.Distance (player.position, this.transform.position) < 10) {
Vector3 direction = player.position - this.transform.position;
direction.y = 0;
this.transform.rotation = Quaternion.Slerp (this.transform.rotation, Quaternion.LookRotation (direction), 0.1f);
anim.SetBool ("isIdle", false);
if (direction.magnitude > 3) {
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);
}
}
}
