Get mouse speed

New releases and general discussions.

Post » Sun Mar 16, 2008 7:28 pm

There doesn't seem to be a way to get the x or y speed of the mouse. I think this would be a good feature to add to the mouse and keyboard object.

I was going to try to make a miniature golf example where you putt using the mouse. The faster you move the mouse, the harder you hit. It could also be used with other game types like billiards (although the ball physics might be difficult, but then again I haven't tried it) and all sorts of pretty unique ideas and gameplay types (maybe using the mouse for boxing or sword slashing for example).
B
2
S
2
G
4
Posts: 153
Reputation: 1,756

Post » Sun Mar 16, 2008 8:36 pm

you could just store the x and y positions of the mouse and then at a later point in time, compare with the store positions with the current position and get the difference.
B
2
S
2
G
5
Posts: 293
Reputation: 2,236

Post » Sun Mar 16, 2008 8:47 pm

Like this [url:3uknvqye]http://www.box.net/shared/16vcyj64o8[/url:3uknvqye]
B
4
S
2
G
4
Posts: 719
Reputation: 2,938

Post » Sun Mar 16, 2008 9:27 pm

Hmm.. I didn't think of that. I'm going to have to try that out and see how well it works, maybe later. I still think a mouse speed option would be good thing to add, in terms of efficiency. But I guess that works too.
B
2
S
2
G
4
Posts: 153
Reputation: 1,756

Post » Sun Mar 16, 2008 10:28 pm

It'd be a good expression to add, yeah. However in the meantime you can use a workaround by using two global variables to store the old x/y, and using a Distance expression to calculate the distance:

+ Always
: Set 'Mouse Speed' to distance(MouseX, MouseY, global('OldX'), global('OldY'))
: Set 'OldX' to MouseX
: Set 'OldY' to MouseY

'Mouse Speed' will contain the distance the mouse moved since the last frame, which is effectively its speed.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Sun Mar 16, 2008 10:46 pm

[quote="Ashley":1hv014uh]It'd be a good expression to add, yeah. However in the meantime you can use a workaround by using two global variables to store the old x/y, and using a Distance expression to calculate the distance:

+ Always
: Set 'Mouse Speed' to distance(MouseX, MouseY, global('OldX'), global('OldY'))
: Set 'OldX' to MouseX
: Set 'OldY' to MouseY

'Mouse Speed' will contain the distance the mouse moved since the last frame, which is effectively its speed.[/quote:1hv014uh]

Yeah, I understand. It makes sense to me. I'll just use this then, or at least for now anyway.
B
2
S
2
G
4
Posts: 153
Reputation: 1,756


Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 1 guest