- Home /
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!
Answer by robertbu · May 22, 2013 at 05:49 PM
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;
Thanks! Worked like a charm. I feel dumb for not thinking of that. I guess I tried too complex with rotation angles and vectors and didn't even consider changing the Y of the hit point..
Your answer
![](https://koobas.hobune.stream/wayback/20220613102732im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Make object lay flat on a sphere + look up? 0 Answers
Issue when freezing Quaternion rotation in one axis? 1 Answer
Rotating an object in relation to its endpoints 1 Answer
Quaternion.LookRotation only on Y axis 0 Answers
How can I angle an image along an line renderer and maintain a look-at-camera rotation? 0 Answers