• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

How to reduce mouse speed?

N

n3wb13

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

Perseus

Not Medusa
Forum Staff
Moderator
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.
 
N

n3wb13

Guest
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.
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?
 
N

n3wb13

Guest
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?
Exactly, how I would do it. :)
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?
 

NightFrost

Member
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:

Perseus

Not Medusa
Forum Staff
Moderator
Anyways what extension are you referring to?
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.
 

RangerX

Member
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.
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)
 
L

leodar

Guest
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.
 
Top