Hi, I’m making a player character that moves with the mouse cursor, using:
position = get_global_mouse_position()
I would like to get the mouse movement relative to the previous frame as a Vector2, since this would allow me to control the sprite animations, like this for example:
InputEvent is an object which tells us what happened in inputs on a frame, so we need an instance to deal with.
We can get it in _input(InputEvent event) for example (I think this function is called whenever InputEvent object is instanciated). There is _gui_input(InputEvent event) too but it is about events happened on a control node.
What do you mean exactly when you say “we need an instance to deal with”?
I am trying to use the same InputEventMouseMotion.relative Vector2 value for my game items to know where the mouse is located, and to then run another function that will move them to my cursor to collect them.
However, I am just not wrapping my head around the idea behind what InputEventMouseMotion is, or how to handle InputEvents in general.
The following is my understanding, which may be incorrect.
In godot, when an input event happens (mouse moved, mouse clicked, etc.), an InputEvent object is created. It holds the information what happened. It is eventually passed to functions like _input(event).
In this function you have event so you can see the contents of the event. One point here is that _input(event) would be called for any input event, so we need to filter as in mq95’s post.
We can (should) not get any instance of event directly from InputEvent class itself.
There are two more points.
Input class is confusing. This is somewhat static so you can see directly what input is given.
If you want mouse position only, you can use get_{global, local}_mouse_position() function.