Make object face perpendicular to the target

Hi,

I’m using this script to make an enemy face the player:

        Vector3 direction = (player.position - transform.position).normalized;
        Quaternion lookRotation = Quaternion.LookRotation(new Vector3(direction.x, 0, direction.z));
        transform.rotation = lookRotation;

However, the animation I have makes the character look to their left, so it constantly looks like it’s off by 90 degrees.

How can I adjust the script so the enemy faces towards the player?

Personally, I would much rather change the animation to make it so the character faces the correct way. If you leave the animation looking to the left like that by default, it’ll cause headaches later on.

If that’s not an option for some reason, you could always just add or subtract 90 to the Vector3 inside of LookRotation.

1 Like

How would you suggest I do that?

The other suggestion isn’t working properly. Do you have a suggestion for what I should put in the code?

Well, if this is a Unity animation, you would just have to redo your keyframes but facing the correct way, right?

If not, then you would have to open up whatever software you used to create your animations and it should be simple to rotate it 90 degrees.

As for the code suggestion, what did you try?

I’ll probably just use animation rigging to point at the player, I suppose. I just adjusted the value in the vector to …LookRotation(new Vector3 -.2f +…