Hey guys,
Im trying to script a tank turret and im getting stuck with the math involved to make the gun point at the mouse’s direction.
this is how the Camera is setup relative to the tank, and the mouse is locked to first person, so the mouse cant move freely around the screen (this is so that you dont have to Rightclick & drag the pan the camera around)
the gun is attached by a hingeconstraint, which will then set the target angle based on the mouse’s 3D orientation relative to the camera
as you can see by my horrible diagram above, the gun doesnt point at the target.
the effect that im trying to achieve is the following;
in this case, the mouse is pointing at 0 degrees relative to the camera, and the gun will also point at the target, but the angle (x) here is unknown.
does anybody know which math functions i need to utilize in order to figure out what angle X should be?