Getting the speed of mouse movement?

(Brvdbury) #1

Is there a way, in Python, to get the speed of the mouse when it’s moving?

0 Likes

(Daedalus_MDW) #2

yes, you compare the current and previous mouse coords

0 Likes

(Nicholas_A) #3

velocity = distance / time

distance would be sqrt((curr.x-prev.x)**2-(curr.y-prev.y)**2)
where curr is the current coordinates of the mouse and prev is the previous.
on init, assign prev to curr but set prev at the end of the function.

then for time, you could us time.time() or a timer property or just some value.

0 Likes

(TheDave) #4

That. Also, for FPS games, you would also usually reset the mouse position to the middle of the screen after getting the co-ordinates to stop the mouse from flying off the side.

0 Likes

(Daedalus_MDW) #5

at the bottom of the file is what i use for mouselooking. its much better then traditional recenter every frame.

0 Likes