Help with look_at() function

Godot Version



I have a Node2D called StickAbility which has the below code:

func _process(delta):

This node is attached as a child to a CharacterBody2D called Player.

When my player walks forward (Vector2.UP) the Node2D that should look at the global mouse position moves. Even though I am not moving the mouse. I don’t really understand what is going on here.

Here is a gif which hopefully demonstrates the problem. You can see as soon as the player walks forward, the stick moves even though the mouse hasn’t.

Here is my Player code which StickAbility is attached to:

extends CharacterBody2D

@onready var velocity_component = $VelocityComponent as VelocityComponent
@onready var stick_ability = $StickAbility

var base_speed = 0

func _ready():
	base_speed = velocity_component.max_speed

func _process(delta):
	var movement_vector = get_movement_vector()
	var direction = movement_vector.normalized()

func get_movement_vector():
	var x_movement = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
	var y_movement = Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
	return Vector2(x_movement, y_movement)

Does this work for the Node2D?

func _process(delta):

this look_at(get_global_mouse_position()) should already cover what you need no? because the node who has this line of code should already be facing where the mouse at

i see no problem with the look_at function

i think your issues is sword’s image pivot

the code i use:

@export var sword:Sprite2D

func _process(delta):