playMaker

Author Topic: [SOLVED] Telling the difference between mouse button drag and click  (Read 3836 times)

jwvanderbeck

  • Playmaker Newbie
  • *
  • Posts: 18
Hello.

I have two states that are based on a mouse click.

Left mouse button and drag pans the camera.  I have this working fine.
Left mouse button click selects an object or point.  I have this working fine.

What I can't figure out how to do is how to get both working together.  I can't figure out how to transition to the proper state without one or the other taking precedence.

Is there a way to define a transition that essentially says "If the mouse button is down and the mouseX/Y is changing, then do this transition"?
« Last Edit: December 10, 2014, 12:23:08 PM by jwvanderbeck »

jwvanderbeck

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Telling the difference between mouse button drag and click
« Reply #1 on: December 10, 2014, 12:22:46 PM »
I managed to get this working.  The trick was understanding that the Mouse Pick action doesn't fire on a left click, which I erroneously thought.  It just fires a ray from the mouse position at any time requested, regardless of the state of the mouse.

So what I did was on Left Button Down I transition to a new state, "Left Button Down".  In that state I have three actions.  In one action I get the mouse movement (Get Axis Vector with axis of Mouse X and Mouse Y) and store the magnitude in a float.  In another action I use Float Changed to send a transition "Mouse Movement" if that float changes.  The last action is Get Mouse Button Up and fires a transition "Left Mouse Up".

"Mouse Movement" transitions to another state "Pan With Mouse" where I handle my panning.  "Left Mouse Up" transitions to a state "Mouse Up After Click" where I perform the Mouse Pick and carry on as normal from there.

So in a nutshell after I see the user has pressed the left mouse button down, I then look to see if he moved the mouse before he released the button.  If he releases the button without moving the mouse, then I transition to a pick, and if he moved the mouse first, I transition to a pan.


Tack

  • Playmaker Newbie
  • *
  • Posts: 14
Re: [SOLVED] Telling the difference between mouse button drag and click
« Reply #2 on: December 10, 2014, 02:45:24 PM »
I'd like to thank you for coming back and posing the answer with a screenshot. This is extremely helpful!

jwvanderbeck

  • Playmaker Newbie
  • *
  • Posts: 18
Re: [SOLVED] Telling the difference between mouse button drag and click
« Reply #3 on: December 10, 2014, 04:38:18 PM »
I'd like to thank you for coming back and posing the answer with a screenshot. This is extremely helpful!

You're welcome.  Nothing makes me crazier than finding someone else who solved the same problem I had in a search, only to see they didn't say how they solved it.  So I always try to follow up for future posterity.  For all I know, I might be solving my own problem again sometime in the future :)

slcrubes

  • Playmaker Newbie
  • *
  • Posts: 4
Re: [SOLVED] Telling the difference between mouse button drag and click
« Reply #4 on: September 20, 2015, 06:39:42 PM »
Agreed...this is exactly what I was looking for. Thanks for posting that solution.