0 votes

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?

Godot version 3.4.2
in Engine by (93 points)

2 Answers

0 votes
Best answer

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.

by (93 points)
+1 vote

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
by (445 points)
edited by

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!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.