The Daily Click ::. Forums ::. Klik Coding Help ::. Direction/Speed/Distance of mouse cursor.
 

Post Reply  Post Oekaki 
 

Posted By Message

Buster

BLING COMMANDER

Registered
  03/06/2002
Points
  1545

VIP Member
25th January, 2011 at 07:33:34 -

What would be the best way to detect the direction the mouse cursor is moving in? It'd be even better if I could figure out a way to test the speed and distance it was moved also.

 

Hagar

Administrator
Old klik fart

Registered
  20/02/2002
Points
  1692

You've Been Circy'd!Teddy Bear
25th January, 2011 at 09:00:02 -

BUSTER! Welcome back dude! and hope life is treating you well. Iklik-it survivors are few and far between now

About to go into work (well my lab), but I will try to make an example tonight. My idea is this, you update a set of variables every always. Looking at the previous set of xy vals and the current set allows for some trigonmetry to find the angle of the right hand traingle (and hence direction) and the distance (pyhthagoras).

Also where are Ashman and Muggus?

 
n/a

Hayo

Stone Goose

Registered
  15/08/2002
Points
  6946

Game of the Week WinnerHas Donated, Thank You!VIP MemberGOTM 3RD PLACE! - APRIL 2009Weekly Picture Me This Round 27 Winner!Weekly Picture Me This Round 41 Winner!Weekly Picture Me This Round 45 Winner!
25th January, 2011 at 16:09:45 -

Buster!!

Stay with us this time, we killed Phizzy and we are keeping Adam on a chain!

 
www.hayovanreek.nl

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49566

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
25th January, 2011 at 16:44:05 -

Like so, order of events is important

Have a active object store values for your calculations
We'll call it "MouseValues"

Use the following formulas to retrieve mouse data:
Speed(Or Pixel Distance Per Loop)- sqrt((xmouse-OldX("MouseValues")) pow 2 + (ymouse-OldY("MouseValues") pow 2)

I can't remember the angle formula right now, but an easy (32 direction) way of doing it would be to position an object at the mouse and position and object at the OldX and OldY position and make the object at the mouse look at it then retrieve it's direction.

(Make sure this condition comes after your calculations)
Always-
-Set OldX of "MouseValues" to xmouse
-Set OldY of "MouseValues" to ymouse

 
n/a

Hagar

Administrator
Old klik fart

Registered
  20/02/2002
Points
  1692

You've Been Circy'd!Teddy Bear
26th January, 2011 at 00:12:26 -

Just to add to this, if you want 360 degree direction goodness it will be mostly exactly as Urban Monk says:

set speedperalways to Sqr(((XMouse-xold( "Active" )) pow 2)+((YMouse-yold( "Active" )) pow 2))
set myangleto ATan2(YMouse-yold( "Active" ), XMouse-xold( "Active" ))
set xold tp XMouse
set yold to YMouse

Then set some counters from those alterable values to view them. In this example right will 0 degrees, up will be -90 down will be 90 and left will be 180. Some averaging maybe handy if you wish to smooth things out.

I have made a little example, if you want a copy PM me your email address. Do you have MMF2 Buster? I dont think the Atan2 function exists in MMF1.5.

And as Hayo says, stick around!


 
n/a

Buster

BLING COMMANDER

Registered
  03/06/2002
Points
  1545

VIP Member
27th January, 2011 at 12:00:05 -

Hey guys! Long time no see! Yeah life is swell, haha. How's life treating you?
Ashman is still alive and kickin'. Haven't talked to Muggus for years though! How are you guys?

Thanks for all your suggestions. I'm a bit confused with some of the code. I'd love to see it in example if you have time to make one for me Hagar. I'll send you a message on here with my e-mail address.


 

Hagar

Administrator
Old klik fart

Registered
  20/02/2002
Points
  1692

You've Been Circy'd!Teddy Bear
27th January, 2011 at 16:24:56 -

Sent you some examples, hope they help!

I keep threatening to do proper tutorials on these type of things (plus electronics, basic engineering) but there is never quite enough hours in the day

 
n/a
   

Post Reply



 



Advertisement

Worth A Click