Get mouse speed

This forum is currently in read-only mode.
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • 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).

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

  • 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.

  • 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.

    Yeah, I understand. It makes sense to me. I'll just use this then, or at least for now anyway.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)