# Help trying to set an angle based on the mouse's orientation

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?

1 Like

well, then u shouldn’t be using the same numbers to begin with. Calculate the shot from the cannon to mouse hit… the real problem is a near miss: Mouse hit may be in 30 studs up a far-away tree, or thousand studs away in the sky… i never did figure that one out…
Even throwing a football; had that problem.
I’m guessing u shouldn’t be using mouse hit here: prolly have to make your own reticule based on where the gun is actually facing and shooting there too. Math anyone…?

After spending over 30 hours trying to figure this out, i finally got the solution.

i forgot to add the tank model to mouse.TargetFilter…