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

2 comments

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

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.