#LookRotation on a child object

1 messages · Page 1 of 1 (latest)

next pewter
#

Working on a tank game and I just found a problem with my guns rotation:
Rotation works perfectly when the parent object is level x rotation = 0 however if the tank is at an angle i. e. climbing a hill my system does not work anymore

I have posted some images to visualize how my system works and that is the issue.

#

I should also mention this is a 3d game

#

and the target is in the middle of the screen (it is at the crosshair at a raycast that shoots from the camera and detects collision)

#

I believe that the offset of the gun is exactly the tanks rotation

#

meaning that if the tank is tilted by 20 degrees the gun is also 20 degrees off

#

However I cant just fix it by adding the tanks rotation as the rotation of the gun has to also depend on where the gun is facing i. e. if the gun is facing left the 20 degrees shall not be added as the gun is level in theory