Tank Game Dev Log #6: Camera Aim

Added mouse aim / camera aim

  ยท   1 min read

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:

  1. raycast from the camera & obtain the hit-point
  2. get a direction vector from the gun tor the hit-point
  3. 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)
  4. calculate the pitch & yaw from the relative direction
  5. tell the turret to rotate & gun to aim up/down based on the current pitch & yaw VS target pitch & yaw
  6. add some min-max pitch constraint
  7. viola!

Gallery #