Getting the mouse position and moving an object using it is extremely laggy.

Godot Version

4.3

Question

extends Node2D

var arm_length = 0  # Fixed arm length (adjust as needed)
var arm_socket_offset:Vector2 = Vector2(8, -24)
# Variable to throttle mouse updates
var mouse_update_delay = 0.1  # Update every 0.05 seconds (20 updates per second)
var time_since_last_update = 0.0
func _input(event: InputEvent) -> void:
	if event is InputEventMouseMotion:
		if time_since_last_update < mouse_update_delay:
			pass
		look_at(get_global_mouse_position())
func _process(delta: float) -> void:
	time_since_last_update += delta

Using the script above to get the mouse position and rotate an objects is extremely laggy for some reasons. Here is a video showcasing the lag:

This shouldn’t cause such lag spikes. I just tested this piece of code and it is buttery smooth for me.
Maybe try to look into the profiler to see if this script is definitely the rootcause of your lags, or maybe there is some other process that is running very inefficiently.