playMaker

Author Topic: Track Mouse Movement Request  (Read 5854 times)

miroac

  • Playmaker Newbie
  • *
  • Posts: 3
Track Mouse Movement Request
« on: January 05, 2012, 04:00:31 AM »
Hey there,
I currently need an Action that allows me to get the current direction in which the mouse is moving for the X and Y axis that can be stored in a variable.
For example, when moving your mouse to the right the variable would read back a positive number value, negative for left.
On the Y axis it would be positive for mouse movements upwards and negative for downward motions.
It also needs to be done in realtime.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Track Mouse Movement Request
« Reply #1 on: January 05, 2012, 09:58:08 AM »
Hi,

 Interesting :)

 You can actually do that with the existing set of actions.

three variables:
-- the current position of the mouse
-- the previous position of the mouse
-- the direction of the mouse

 This is the series of step you need to implement this

1: Record the current position of the mouse.
2: substract the current position with the previous position-> this is your mouse movement direction
3: copy the current position in the previous position

I'll look into doing a custom action for this if I have time during the week end.

Do you need to trigger events based on where the mouse is going or do you the actual real direction ( like going left, right top bottom and that's it? or the real values?

Bye,

 Jean




Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Track Mouse Movement Request
« Reply #2 on: January 05, 2012, 10:35:34 AM »
You can also use Get Axis with "Mouse X" and "Mouse Y" to get the mouse movement each frame.

I've been meaning to add a browse button for Get Axis to list the built in axis - since they tend to get forgotten...

miroac

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Track Mouse Movement Request
« Reply #3 on: January 10, 2012, 10:49:33 AM »
Do you need to trigger events based on where the mouse is going or do you the actual real direction ( like going left, right top bottom and that's it? or the real values?

Thanks for the response, I was going to use the real values to calculate whether it was going left, right, up or down.

What I'm trying to do is trigger an event based on whether the mouse is going in a particular direction when the mouse button is clicked.

So if dominately going to the right and then you click, the animation for swinging your club from the right plays (to the point until it is being held behind the body) then when you release it will then complete the swing.

Hope that helps a little more with the extra info.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Track Mouse Movement Request
« Reply #4 on: January 11, 2012, 12:44:28 AM »
Hi,

 Ok, I see.

I actually started experimenting with an action for this but then Alex was right to point that GetAxis actually has the potential to give you all you need to work this out.

 Tho, the custom action I did allows you more in one go so I think it will be useful.

 I got carried away with this, so you can track movements with or without mouse clicks, and sample every nth frame. It returns both the x and y delta movement but also returns the angle.

 So in your case, I would start considering storing the angle in an array ( using arrayMaker for example :) ) so that you always get for example the last ten angles of the mouse movement, and on mouse click, you study the variation of them angles ( so that it is in the same quadrant for example or that the maximum difference doesn't exceed a certain amount). Else you might get away with the last angle of the mouse direction when the user clicks. it might be enough for your needs.

This would need testing and validating of course. but that would be the way I would start handling this.

Bye,

 Jean

 

miroac

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Track Mouse Movement Request
« Reply #5 on: January 11, 2012, 06:53:51 AM »
Thanks for the help so far Jean. I was tinkering with your script and I think I may be able to use it.
Though I'll probably need to start another thread for comparing XY values against each other though.
Pretty much what I've done so far is have it so that I have a state using your script and constantly storing the Vector3 result, then I have another action simply looking for when I click the mouse. Then it jumps to the next state and the last result is stored.
Only problem now is that I have the Vector values, for example, -2, -1, 0, but I can't figure out a way to tell the script that since the X vector is the higher movement value it is the dominately moving to the left :S.
It is possible to adjust your script so that each vector3 value, X, Y and Z can be stored in a float?
« Last Edit: January 11, 2012, 07:00:52 AM by miroac »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Track Mouse Movement Request
« Reply #6 on: January 13, 2012, 01:19:30 AM »
Hi Michael,

You can toggle the "normalize" toggle and you will get the delta progression as a percentage of the screensize ( width and height being equal to 1)

 but you don't need that to evaluate the direction I think.

Two solutions:

1: using the delta position:
 if x is negative, it's going left, ir x is positive it's going right
if y is positive it's going up, if y is negative it's going down.

 if going left and up, then it's going for the top left of the screen, if right and down, it's going for the bottom right and so on.

2: using the angle:

 angle of 0 means it's going right
angle of 180, means it's going left
angle of 45 means it's going for the top right screen more or less

Using angles, you only need to evaluate one variable, and that can be done using one action "float switch"

 I have attached a screenshot of a possible set up for checking the angle.

 Hope it helps,

 Bye,

 Jean