I made a reticle for my game that follows the mouse cursor (by setting its position in the _input() callback). This works fine, except that the reticle's position updates one frame later than the real (system) cursor does. This makes the reticle feel "sluggish". I was wondering if there was any way to fix or mitigate this delay, as it's pretty annoying. (video attached for an example)
#Cursor reticle is delayed by 1 frame
1 messages · Page 1 of 1 (latest)
bump
Godot's _input(event) reacts only when an InputEvent is sent by the OS.
_process(delta) runs at each frame.
To me it seems like you want to have this run indefinitely. If that's the case, try checking for the input in your _process() function with the Input Singleton
Godot Engine documentation
Inherits: Object A singleton for handling inputs. Description: The Input singleton handles key presses, mouse buttons and movement, gamepads, and input actions. Actions and their events can be set ...
What does your 'cursor position' script look like? Are you updating the value
as-is, or are you running it through an interpolation function?
While not necessarily as efficient, you can opt to use
'CanvasItem::get_global_mouse_position' or 'DisplayServer::mouse_get_position
[for screen-space coords]' to grab the user's cursor position directly from
anywhere.
Relevant docs:
https://docs.godotengine.org/en/stable/classes/class_displayserver.html#class-displayserver-method-mouse-get-position
Godot Engine documentation
Inherits: Object A server interface for low-level window management. Description: DisplayServer handles everything related to window management. It is separated from OS as a single operating system...
Godot Engine documentation
Inherits: Node< Object Inherited By: Control, Node2D Abstract base class for everything in 2D space. Description: Abstract base class for everything in 2D space. Canvas items are laid out in a tree...
This is the script that updates the reticle's position:
func _input(event: InputEvent) -> void:
if event is InputEventMouseMotion:
position = event.position
no interpolation or anything