Is there a way to code a weapon that circles the player?

Godot Version

4.6.2

Is there a way we’re I can have a node orbit my player but the orbiting node changes its degrees by where the mouse is.

I tried looking up a video, but all of them boil down to ‘look_at(get_global_mouse_position)’

This a top-down Rouge-like

Please, this is vital to my game

I don’t know what precisely you are asking …

You can get the mouse position yes, and you can have a Node orbit the player, and you can have that Node point towards a point in space that is defined by where your mouse is.

But what is your issue currently ?
Are you struggling to implement it ?

1 Like

You can use pretty standard mouse-look code to rotate a pivot + offset camera

In this example scene tree you could rotate the Pivot’s Y axis and the SpringArm3D’s X axis. You do not have to use a SpringArm3D but it can help prevent the camera from clipping out of bounds.

Oh sorry I saw “orbit” (and your last post) and assumed you were wanting a camera.

You are finding good advice, look at will work fine with an offset node. You can use look_at on the pivot.

1 Like

Are you trying to create a 3rd person controller? If so, I recommend you check out my Camera3D Plugin, which has code for that. You can look at it and steal it or use the plugin. If you want to use it, you can also check out my Character3D Plugin, which has an example of using it.

I want it to orbit the player, but change where its orbiting from the direction of the mouse is to the player

I think I made the description kinda vague, but it’s a 2d top-down Rouge-like, with the orbiting node being a gun

I new, like really new to coding. Could you dumb it down and give me some code, please and thank you?

You could use the sample you posted in _process, assuming this script is attached to the character body and Pivot is a direct child.

@onready var pivot: Node2D = $Pivot
func _process(_delta: float) -> void:
	pivot.look_at(get_global_mouse_position())
2 Likes

green is the player.

yellow is the node (gun).

i want the gun to orbit around the player depended on where the mouse is to the player