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?
1 Answer
1Hello!
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.
Hello! Could you post some images about the problem, a brief sketch what you want. My best guess is that you used world axes when you rotated the object. Instead 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.
– Lewwwer[74260-1.jpg|74260]
– TacticalCow