Help pivoting arm to follow the mouse (AIM)

Godot Version

V4.3 stable

Question

Hello all, I’ve been struggling with getting the sprite arm of my character to follow the mouse properly, I’m pivoting it from the middle of the shoulder but I want the tip of the gun to follow the mouse, here’s what I’ve doe so far:

extends Sprite2D

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	pass # Replace with function body.

func _process(delta: float) -> void:
	var mouse_position = get_global_mouse_position()
	var direction = mouse_position
	var desired_rotation =  direction.angle()

	rotation_degrees = clamp(rad_to_deg(desired_rotation), -115, 0)

and this is the arm:


I tried getting the tip offset but couldn’t make it work, so what happens is what is following the mouse angle is the shoulder and so the gun is waaaay out of place of where it should be aiming, any ideas, I started yesterday so I’m pretty new to the engine but I did some googling and couldn’t come up with a solution to this,

Thank you in advance

You can try to use the look_at() function, tho i am not sure if that will help, i mainly work with 3D so this answer can be completly wrong, just my guess from what i know…

Yeah I tried that but it does the same thing, it rotates but the actual gun is not whats following the mouse, rather the offset point

would you mind sharing some pictures so its easier to see what the problem is? (I get that its oriented wrong, but pictures would help a lot)

I assume your mouse is in front of the character, in which case it might be because by default the arm is pointing down and not forward (to the right), you could try rotating the arm sprite so it points right, and still keeping the pivot point at the shoulder, in theory that should fix it.

Yeah so my mouse was actually down in the right side corner, but if I move it up to the middle the point of the gun doesnt follow, only after the mouse is way higher than the character

But I’ll try changing the starting position too, I’ll let you know

1 Like

Nope, no luck