Home > Back-end >  GameObject rotates on the wrong Axes to the player
GameObject rotates on the wrong Axes to the player

Time:02-12

I got a top down game and i am trying to make bots work. I made them walk in a random Direction every few seconds. Now I want them to look at my player: I did that with first calculating the Vector3 Target posision

Vector3 Targetpos = GameObject.Find("Player").transform.position - transform.position;

Then i set my transform.rotation to that variable.

transform.rotation = Quaternion.LookRotation(Targetpos, Vector3.zero);

Now, my Bot is Rotating to my Player but he is rotating on the X Axes instead of the Z

enter image description here

CodePudding user response:

To Rotate around Z-axis you'll have to use Vector3.forward

transform.rotation = Quaternion.LookRotation(Targetpos, Vector3.forward);

Refer the Documentation.

  • Related