Camera Aim #
I want to be able to aim the gun while in the third person camera. Because normally turret doesn’t have roll control, there is some constraint that the rotations should be in pitch & yaw rotation only. I do this by:
- raycast from the camera & obtain the hit-point
- get a direction vector from the gun tor the hit-point
- translate the direction into direction relative the the turret’s transform (which may not have the same axis as the world due to inclined ground) using
transform.InverseTransformDirection(direction) - calculate the pitch & yaw from the relative direction
- tell the turret to rotate & gun to aim up/down based on the current pitch & yaw VS target pitch & yaw
- add some min-max pitch constraint
- viola!
added third person mouse / camera aim!๐ฆ
— meisbkkkkkkk (@meisbk) May 18, 2025
with pitch min-max limit
works on inclined ground too
tbh i found that you can translate the target vector to the turret's local vector and that made things way easier to work with
(i was trying to "rotate" the pitch and yaw) https://t.co/Qbw2rjGuU4 pic.twitter.com/1Q77E7oEpl