Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to Rotate my tank gun barrel so it is facing towards the mouse?

Asked by 5 years ago

I have been stuck on trying to implement this feature for days ):

I am currently making a 2D tank game and I have the camera and movement down now I just want to my tank's gun barrel to rotate with the mouse however when I change it's cframe the entire tank moves Im guessing due to the barrel being welded to the main body

https://i.imgur.com/yoXsaCC.png https://i.imgur.com/ZMCsrHF.png https://i.imgur.com/Wndob3d.png

0
Instead of a weld, you could use a CylindricalConstraint with an angular servo. Then by changing the target angle, the barrel will rotate. You would just need to do some math to get the right angle based on the mouse position vector3_zero 1056 — 5y
0
If you go the angles route, this (https://scriptinghelpers.org/questions/77066/#72315) might help you with the maths required. Alternatively, you could use a body gyro. fredfishy 833 — 5y

Answer this question