How to fix rotation point?

Godot Version



Im trying to make a gun rotate around the player following the mouse and It works however the issue is the rotation point is at the top left corner of the view port rather then where I have the pivot set which is inside the player (3D)

at least show your scene tree so we know how you set the camera, gun, and player in your scene tree

1 Like

thanks for sharing, but where do you put the gun node/scene?

Oh I for got to switch the scenes when i took the picture and im not home currently so il try my best to explain

I made the gun in its own separate scene because the player will be able to modify the guns stats and shape (not sure if a separate scene would be needed)

But for how i have it set
The gun scene i set as a child node to the player scene

Within the gun scene:

Node3d “gun”
Node3d “pivot”
|__node3d “gun model” script

with this, you rotate the Base Node3D “gun” or the “pivot” Node3D?
you said you just put this scene as a child of the player

sorry it took so long but i am rotating the pivot node3d and yes i have the whole gun scene as a child to the player

Your script has the model looking at a improper position. get_mouse_position() is in pixel-by-pixel screen coordinates, you need to either translate those to meters in world coordinates, or find a new way to calculate rotation. If your player’s location is stationary on the screen then you can keep the mouse in screen coordinates and find rotation relative to that.

1 Like