I was doing some basic enemy AI and it works, but the whole enemy model moves when player jumps. Is there any simple way to lock Y axis? I´m new with code.
This is my script:
void Update()
{
animator.SetFloat("Speed", agent.velocity.magnitude / agent.speed);
if(timePassed >= attackCD)
{
if (Vector3.Distance(player.transform.position, transform.position) <= attackRange)
{
animator.SetTrigger("Attack");
timePassed = 0;
}
}
timePassed += Time.deltaTime;
if (newDestinationCD <= 0 && Vector3.Distance(player.transform.position, transform. position) <= aggroRange)
{
newDestinationCD = 0.5f;
agent.SetDestination(player.transform.position);
}
newDestinationCD -= 0.5f;
transform.LookAt(player.transform);
}