Rotate a 3D model left or right only

So I have a tank model in a point-and-click game. The way I’m doing it is if you right click a location, the turret on the tank rotates to that location but not the base of the tank itself.

I’m using:

obj.transform.rotation = Quaternion.Slerp(obj.transform.rotation, Quaternion.LookRotation(myhit2.point - obj.transform.position), Time.fixedDeltaTime * 3);

However if you click at the top of a building, the raycast point is not at the same plane as the turret and it will point up at the top of the building. This makes the turret in the model rotate funny and clip the model as it’s a left/right articulating turret only.

My question is, how can I get the turret to rotate in the direction of the hit point, but not look up at it (i’ll be shooting at other tanks and wont need to aim up).

Thanks!

The easiest way to solve this problem is to bring the ‘y’ value of the hit point down to the level you want it:

var v3 = myhitZ.point;
v3.y = obj.transform.position.y;

Now use the v3 in your Slerp() in place of the myHitZ.point;