- Home /
Turret and Cannon compensate for Z axis
I have a tank with:
-a turret that rotates on the y axis (Horizontal)
-a cannon that rotates on the x axis (Vertical) Raycasts to target then adds x angle to compensate for arc
Everything works as long as the z axis of the entire tank is 0. I run into a problem when the tank rolls at all and the aim is thrown entirely off.
Are there any equations/math that accounts for z? Possible to get something like X Y = Z?
Hello!
Could you post some images about the problem, a brief sketch what you want.
$$anonymous$$y best guess is that you used world axes when you rotated the object. Ins$$anonymous$$d of rotating with Rotate(Vector3 angles); you should use Rotate(Vector3 angles, Space.Self); It rotates the object around its local vectors. Or when setting the rotation use localRotation.
Hope it helps.
Answer by Lewwwer · Jul 18, 2016 at 06:15 AM
Hello!
Now I see clearly the problem.
I recommend transforming the target position to local position and do the calculations as you did before with this local point, so using the built in function you can get the target point's local coordinates.
Your answer
![](https://koobas.hobune.stream/wayback/20220612084916im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can I rotate a tank's turret back to the starting turret position? 2 Answers
Tank urret rotation - Need help. 1 Answer
Quaternion Rotation On Specific Axis Issue 0 Answers
Calculate rotation angle for two side of cube ( like dice ) from Quaternion.identity 0 Answers
Look at like rotating around y axis 1 Answer