Godot Version
4.1.1
Question
I have a Node2D called StickAbility which has the below code:
func _process(delta):
look_at(get_global_mouse_position().rotated(PI/2))
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()
velocity_component.accelerate_in_direction(direction)
velocity_component.move(self)
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)