How can you get duration of InputEventMouseMotion?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By YangTegap

I have a game with a navigable map. You can select items on the map, but you can also click and drag to maneuver around the map. I don’t want to accidentally select items while navigating the map, so I have a variable called dragged that indicates whether or not the mouse has been dragged after being clicked. When the mouse is released over an object on the map, it is only selected if dragged == false

Here’s the conundrum. This works perfectly EXCEPT for the fact that if I move the mouse even one pixel after clicking then I can’t select on any map items. There has to be no mouse movement whatsoever. My players aren’t robots, so this isn’t ideal.

Here is the script that sets dragged to true:

func _input(event):
	if event is InputEventMouseMotion:
		dragged = true

Is there any way to set dragged to true ONLY if InputEventMouseMotion occurs over a set duration, number of frames, or distance in pixels?

:bust_in_silhouette: Reply From: umma

this is basic, but give it try.

var dragged = false
var timer = $animationplayer
#create a animtionplayer node, set the time you want in the animationplayer, i use anmationplayer because it's easier to use than timer node.

func _input(event):
    if event is InputEventMouseMotion:
         timer.play("anim_name")
         dragged = false

#create a signal from the animationplayer node so it emits when the animation is finished, then write.

func _on_animation_player_finished(_anim):
  dragged = true

This is great! Thank you for the suggestion! I wound up actually calculating the distance between the mouse position on mouse down and mouse up, and that gave me just what I needed for my purposes. But thank you so much!

YangTegap | 2022-01-29 20:09

:bust_in_silhouette: Reply From: YangTegap

What worked best for my use case was getting the event.position for mouse down and mouse up, and calculating the distance. I then could give myself a little wiggle room.