I had code set up in my chase was to stop the enemy from following after death which cause him keep sliding but commenting it out it lets enemy follow but then he sliding. I commented next to it what it does and problem where it happening
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class Chase : MonoBehaviour {
public Transform player;
Animator anim;
public Slider healthbar;
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update() {
if (healthbar.value <= 0) return; //This where error is happening this also supposed stop the chase function so that when it dies it will not keep following. but this is also cause him not chase cause seems even though health bar is not 0 it auto kills the chase function
// this for skelenton pov
Vector3 direction = player.position - this.transform.position;
float angle = Vector3.Angle(direction, this.transform.forward);
//have skelenton moving and controlling animations
if (Vector3.Distance(player.position, this.transform.position) < 10 && angle < 30)
{
direction.y = 0;
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);
}
}
}