how do you do something like: transform.LookAt() but freeze the X and Z axis.

How do you do something like: transform.LookAt() but freeze the X and Z axis. I’m trying to make an enemy Airplane script, and i got it working, but i need it to be able to have the Y axis point at the player so it doesn’t completely miss.

http://forum.unity3d.com/threads/36377-transform.LookAt-or-Quaternion.LookRotation-on-1-axis-only

Edit:
Not that big a deal, but please do a search before you create a thread.

you know I went through the same issue, and I tried setting the values to zero and it didnt work for me…

My situation is a little more complicated tho… you see while I want to rotate my turret around one axis only (not too hard), the parent that its sitting on is moving over the terrain generating its own rotations, which adversely affects the child rotation.

I still need to go back and relook at it, because atm im stuck using LookAt then reversing part of the rotation by the amount the parent is rotated.

I did try what they said in that post, but it that’s not doing what i want it to do. By saying point.y = 0.0 and point = player’s poisition, your basically just saying LookAt the player, but a little bit lower than the player (if the player is higher than 0.0 on the y axis). Maybe if would work if you did something like Point.y = transform.position.y so it stays the same height the object that is looking at the player? I’ll try that now.

I think what you may be thinking of is Quaternion.LookRotation

1 Like

your probably right, its all off the top of my head atm

either way I went through all sorts of variations of quaternion functions trying to get the correct behaviour without a lot of luck.

My main problem was I figured I needed to calculate the rotation based on the vehicles direction, of course I was trying to rotate the turret attached to the vehicle to that value which proved to be a real troublemaker.

In the end I got it going, but im going to go back to it at some stage because atm its a snap look rather than nice slow rotation towards the direction

Cool so i tried what i said and it worked. Now to work on spawners and Helicopter AI :frowning: (if your wondering its for a survival mode)