1. Hey! Guest! The 32nd GMC Jam will take place between Feb 22nd, 12:00 UTC (Friday noon) and Feb 25th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

How to reduce mouse speed?

Discussion in 'Game Design, Development And Publishing' started by n3wb13, Jun 20, 2017.

  1. n3wb13

    n3wb13 Member

    Joined:
    Jun 19, 2017
    Posts:
    8
    Hi I'm trying to use the mouse as the controller for my character but I want to set it to a certain speed. If anybody know please help me out. Thanks.
     
  2. Ragarnak

    Ragarnak Not Ragnarök Forum Staff Moderator

    Joined:
    Dec 29, 2016
    Posts:
    948
    You can't manipulate cursor speed without the use of an extension. You can, however, keep an instance which moves towards the mouse coordinates at a certain speed, then use the instance for controlling player movement.

    It might not be viable option depending on how mouse movement affects your gameplay. So if you need a better alternative that suits your needs, please elaborate a bit on that.
     
    n3wb13 likes this.
  3. JackTurbo

    JackTurbo Member

    Joined:
    Oct 19, 2016
    Posts:
    743
    Disable the cursor and create a custom cursor object. Manipulate this object's x/y based on mouse movements. Then use this object for your game logic?
     
    Kenjiro and n3wb13 like this.
  4. n3wb13

    n3wb13 Member

    Joined:
    Jun 19, 2017
    Posts:
    8
    I'm trying to mimic Slither io controls for my android game. I decided to use the mouse global left pressed event to achieve it. The last problem I'm trying to tackle is the speed. So I thought maybe I could reduce the mouse speed/sensitivity. Anyways what extension are you referring to?
     
  5. Kenjiro

    Kenjiro Member

    Joined:
    May 21, 2017
    Posts:
    346
    Hibba dibba da dibba do.
     
    Last edited: Jul 2, 2017
    n3wb13 likes this.
  6. n3wb13

    n3wb13 Member

    Joined:
    Jun 19, 2017
    Posts:
    8
    I really want to test this out. But I don't understand it. First of all what do you mean by disable cursor and how can i do this ? ( my search always ends up with disable :(cursor sprite) Second I'm already manipulating my player x/y base on mouse movements so how can I get a different result out of this? Won't the speed still be the same since it's base on the mouse?
     
  7. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    1,511
    Disable mouse sprite, create a custom mouse pointer sprite and a mouse pointer object, make its starting position middle of the screen, draw it in draw GUI event. After reading mouse speed x/y, halve them before applying them to player movement or custom mouse object position. Clamp mouse object coordinates so it doesn't move outside screen. You've now halved your mouse speed. If you need to click on things, read mouse pointer object position instead of actual mouse position.

    EDIT: thinking over that again, the speed reduction part might not work... since GM gives us mouse position instead of mouse movement, it will clamp to screen edges, and reducing the deltas just clamps the custom pointer into smaller area. I'm unsure if there's any way to get raw motion data out of the mouse instead of having to rely on GM-dictated mouse position data.
     
    Last edited: Jun 20, 2017
    n3wb13 likes this.
  8. Ragarnak

    Ragarnak Not Ragnarök Forum Staff Moderator

    Joined:
    Dec 29, 2016
    Posts:
    948
    I said that assuming you were trying to slow down the cursor on your PC. There isn't a built-in way for that. (It isn't possible on other platforms either, for that matter, without intermediary processing code or instances.) But on Android, things like input work differently, so you don't need an extension. And that's why I asked you to provide more information.

    I have not played slither.io, so I might not be correct about it, but judging from the Play Store preview, it looks like you need to restrict player movement, not that of the mouse. You can easily achieve that by choosing the minimum value from your maximum allowed rotational/movement speed and mouse input received from the player. But an instance following the mouse coordinates at a certain speed (like I suggested above) is still a feasible option. If you're using GMS 2, consider looking into gesture input as well rather than using mouse position directly.
     
    n3wb13 likes this.
  9. RangerX

    RangerX Member

    Joined:
    Jun 20, 2016
    Posts:
    2,571
    What if you clamp the mouse coordinate larger than the screen at the same multiple you divide your custom cursor position with? (like, if you halve the speed of your custom cursor, you clamp the mouse at double the screen size and so on)
     
    n3wb13 likes this.
  10. leodar

    leodar Member

    Joined:
    Feb 1, 2019
    Posts:
    1
    I found a tricky way. It's limited but it woks for a soft speed reducing.

    In creat event :

    mouseDdeltaX=0;
    mouseDdeltaY=0;
    mouseSpeed = 1;

    In step event :

    mouseSpeedX = (window_mouse_get_x()-mouseDeltaX)*deltaTime();
    mouseSpeedY = (window_mouse_get_y()-mouseDeltaY)*deltaTime();
    mouseDeltaX = window_mouse_get_x();
    mouseDeltaY = window_mouse_get_y();
    window_mouse_set(window_mouse_get_x()-mouseSpeedX*mouseSpeed, window_mouse_get_y()-mouseSpeedY*mouseSpeed);

    ("deltaTime()" is just a script which splits delta_time by 100 000.)

    To change the mouse speed, you can just enhance the value of mouseSpeed, but if the value of mouseSpeed is to much high, you'll find yourself with 2 mouses on your screen, I'm not actually sur why yet. But I think This script could be a begining.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice