Player Node with Orbiting Fist

Godot Version

Godot 4.2.1


Hello everyone,

I’m a beginner with Godot and I’m currently working on a project in Godot 4. I’m facing a challenge with programming a player node with an orbiting fist. Essentially, I want the fist to gravitate around the player within a limited radius and follow the mouse cursor. However, I’m encountering an issue where moving the player also moves the center of the fist’s orbit. Additionally, if I don’t position the player at coordinates x=0, y=0 within the scene, it offsets the center of the fist’s orbit as well.

Here’s a brief overview of what I’m trying to achieve:

The player node should have a fist orbiting around it.
The fist should follow the mouse cursor within a limited radius.
Moving the player should not affect the center of the fist’s orbit.
The position of the player should not impact the center of the fist’s orbit.

I’ve tried a few approaches using GDScript, but I haven’t been able to solve this issue yet. If anyone has experience with similar mechanics or has suggestions on how to approach this problem, I would greatly appreciate your help and insights.

Here the script of the fist :

extends CharacterBody2D

@export var radius : int = 10

func _process(delta):
	var mouse_pos = get_global_mouse_position()
	var player_pos = $"../Player".global_transform.origin
	var direction = player_pos - mouse_pos
	if direction.length() > radius:
		direction = direction.normalized() * radius
	position = player_pos - direction

Thank you in advance for any assistance you can provide!

Best regards

Looks llike you want the player to go in the direction of the mouse and the fists to point in the direction of the mouse from the player unless the mouse is in the radius.

Here is my solution:

Scene structure:
–Scene node
------FistNode (type: Node2D)
--------Fist (actual fist with damage box and sprite)

Now the fist has to have an offset to FistNode, because we are going to turn FistNode to make the orbiting animation.


extends CharacterBody2D

@export var radius = 10.0
@export var orbiting_speed = 0.1
@export var player_speed = 1.0

onready var player = $"../Player"
onready var FistNode = player.get_node("FistNode")

func _process(delta):
	var mouse_pos = get_global_mouse_position()
	var direction = mouse_pos-player.global_position
	var distance = direction.length()
	if distance > radius: FistNode.global_position = player.global_position+direction.normalized()*radius
	else: FistNode.global_position = mouse_pos
	FistNode.rotation += orbiting_speed
	move player by direction.normalized()*player_speed

It just occured to me that you might mean the fist orbiting as in boxing, in which case just leave out the rotation code and for good measure throw in a


instead of the

FistNode.rotation += orbiting_speed
1 Like


It worked, thank you very much for taking the time to answer me.

Best regards,

1 Like