Right now I am trying to get my character to face a targeted enemy. Everything works great except for the fact my character will face the targeted enemy on every axis, not just the Y axis.
Here is an example of the bug.
I dont want the character to rotate to face the enemy downward, because of the other glitch i showed in the video where the player can walk backwards into the air. Here is the code I’m using to have the player look at the enemy.
public void lookAtTarget(){
if (target != null) {
Vector3 lookDirection = new Vector3 (Player.position.x, target.position.y, Player.position.z);
rig.transform.rotation = Quaternion.Lerp (rig.transform.rotation, Quaternion.LookRotation (lookDirection.normalized), Time.deltaTime * 12f);
}
}
Ive also tried variations of the lookDirection vector, including
Vector3 lookDirection = new Vector3 (0.0F, target.position.y, 0.0F);
and
Vector3 lookDirection = new Vector3 (target.position.x, 0.0F, target.position.z);
if anyone has any ideas on how to fix this, help would be very much appreciated. I cant seem to get it to work at the moment, no matter what else I try.