How to make object rotate with mouse?

so i have this square that i want to use as a gun and im stuck trying to figure it out, iim trying to have the square atached to the side of the ball somehow without affected the roll of the ball i also want to connect the “gun” to a script that allows it to move around the ball once again without affecting the roll of the ball. Thanks in advance!

i made a picture to show how i want it to be.
— the star represents the mouse position and the line represents where and how the gun should be and rotate

96042-untitled.png

Couple ways you can approach this. For the ball and the gun rotating independently you’re going to want an empty parent object that the two are children of.

You can use another empty gameobject to offset the pivot of the gun so it rotates around the center of the ball. Then find the mouse position and use something like Rotate.LookAt.