Godot Version
Godot 4.2.1
Question
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