Hi,
I have a bug in my script. When player press skill key but he is not in range to attack character is starting to run to enemy to attack, but when enemy is starting to move character is getting crazy and running in random directions.
Can some one help me?
Method movo to enemy:
if (player.oponent != null)
{
if (runtToEnemy)
{
//Char moving
if (Vector3.Distance(transform.position, player.oponent.transform.position) > 3)
{
Quaternion newRotation = Quaternion.LookRotation(player.oponent.transform.position - transform.position, Vector3.forward);
newRotation.x = 0f;
newRotation.z = 0f;
Debug.Log(newRotation);
transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * 20);
playerMove.controller.SimpleMove(transform.forward * playerMove.speed);
animation.CrossFade(playerMove.run.name);
if (Vector3.Distance(transform.position, player.oponent.transform.position) <= range)
{
runtToEnemy = false;
player.resetAttackFunction();
player.specialAttack = true;
inAction = true;
skillKey = false;
}
}
//Char not moveing
else
{
animation.CrossFade(playerMove.idle.name);
}
}
}