Rotate on Y axis only without LookAt

Hello, when I use LookAt function it rotates my tower in all axis which result in it rotating in the ground slightly as it tries to look at the transform of the enemy. Is there a way I can have my tower rotate on Y axis only without using LookAt? I tried many ways and looked through many forums but I cant make it work on mine.

Thanks.

It depends on your code. You’d have to share it. The reason is because it is pointing the forward vector towards the pivot position of the target. If the two objects don’t have pivots on the same plane, it will adjust all axes. You can still use LookAt, you’d just have to adjust the vector you would pass to it.

Hi Zodi,

The tower ‘looks’ at the position of the referenced game object. That game object is very likely the enemy, and the enemy’s mesh is very likely on a child. The parent position is relative to the mesh.

If that’s the case, you could either move the child with the mesh relative to the parent, or you could add an y-offset to the position you pass on to the LookAt method as suggested by bixarrio.


See also:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms