Hey everyone, i am working on a 3rd person point and click game like diablo. I am stuck in a problem where my character moves towards the enemy and when attacking animation occurs, it tilts. On commenting the line of code where my character faces in the direction of enemy[transform.LookAt(targetedEnemy)], the animation works without any tilting.But then my character does not face the enemy . Here’s the code -
void MoveAndAttack()
{
if(targetedEnemy== null)
{
return;
}
navMeshAgent.destination = targetedEnemy.position;
if(!navMeshAgent.pathPending && navMeshAgent.remainingDistance > attackDistance)
{
navMeshAgent.Resume();
walking = true;
}
else if(!navMeshAgent.pathPending && navMeshAgent.remainingDistance <= attackDistance)
{
anim.SetBool("isAttacking", false);
transform.LookAt(targetedEnemy);
Vector3 dirToAttack = targetedEnemy.transform.position - transform.position;
if (Time.time> nextAttack)
{
nextAttack = Time.time + attackRate;
anim.SetBool("isAttacking", true);
}
navMeshAgent.Stop();
walking = false;
}
}