Mouse Control

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!
  • Hi all,

    I've been setting my custom mouse pointer sprite to be at mousex, mousey every tick. I want to instead not let the mouse coordinates define it, but move in response to the mouse being moved - thus allowing me to set a variable sensitivity and effectively control the speed of the mouse. Would be ideal if it used sin/cos to smooth the movement slightly too. Can anyone tell me if there's a way to do this?


  • of course theres a way to do this!

    first youll need to find the mousex?, mousey? as i call them

    ? just meaning change in but thats not important

    to find these, your going to need to make 2 new variables, they can be global or object, doesnt matter really, personally id store them in the cursor sprite just to keep things organised

    then your going to need your everyday vanilla "always" condition.

    make your two variables called MDeltaX and MDeltaY

    then set MDeltaX, to mousex, and MDeltaY to mousey

    simple enough as it is

    now youre going to want to make your event to move the cursor object, ill call the object CursorS since i dont know your cap

    Make sure that you remove all events that change the position of this object in anyway in the events following this, or else it might not work

    so make a new action of "set position" for CursorS

    set X: .x+(mousex-'MDeltaX')*('MouseSpeed')

    set y: .y+(mousey-'MDeltay')*('MouseSpeed')

    this should be ABOVE the set MDeltaX,MDeltaY actions

    MouseSpeed is another variable of CursorS, if you set it to 1, the mouse speed will be normal, 2 will be twice as fast, 0.5 half as fast, etc.

    your code should look as follows:



    CursorS: set position:[quote:qyf8c0xp]set X: .x+(mousex-'MDeltaX')*('MouseSpeed')

    set Y: .y+(mousey-'MDeltay')*('MouseSpeed')

    CursorS: Set 'MDeltaX' to:[quote:qyf8c0xp]MouseX

    CursorS: Set 'MDeltaY' to:[quote:qyf8c0xp]MouseY

    thats it!

    As for smoothing... you wouldnt really need cos or sin, but youd have to make 2 more variables and make them "follow" MdeltaX and MdeltaY, so that they can only gradually change over time

    its a bit complicated:

    youd need 'Mfx' and 'Mfy', and youd need to change the set position event to use those instead of 'MdeltaX/MdeltaY'

    then youd add two new actions above the set position event for CursorS

    set Mfx to: 'Mfx'+('MdeltaX'-'Mfx')*0.5

    set Mfy to: 'Mfy'+('MdeltaY'-'Mfy')*0.5

    you could play around with the 0.5, if you made it closer to 0 it would smooth slower, if you made it closer to 1 it would smooth faster

    your code should look as follows:



    CursorS: Set 'Mfx' to:[quote:qyf8c0xp]'Mfx'+('MdeltaX'-'Mfx')*0.5

    CursorS: Set 'Mfy' to:[quote:qyf8c0xp]'Mfy'+('MdeltaY'-'Mfy')*0.5

    CursorS: set position:[quote:qyf8c0xp]set X: .x+(mousex-'Mfx')*('MouseSpeed')

    set Y: .y+(mousey-'Mfy')*('MouseSpeed')

    CursorS: Set 'MDeltaX' to:[quote:qyf8c0xp]MouseX

    CursorS: Set 'MDeltaY' to:[quote:qyf8c0xp]MouseY

    if any of this doesnt work just ask, i or u might of made a mistake.

  • Cheers for that explanation there Quazi. I have been pondering this question all afternoon, having Aha! moments only to figure out a reason shortly after as to why it wouldn't work. I knew it would come down to finding the change though.

    Is there anyway to get the physical mouses movements read? There is an unfortunate limitation that everything is based off the mouse cursors movement, which stops if you hit the edge of your monitor.

  • oh forgot about that, i believe the mouse and keyboard object can set the mouse cursors position, all you have to do is set it to the center of the monitor after everything in the always and it should work fine

  • Thanks Quazi, this works brilliantly! Very in depth explanation, thanks for going to the trouble

    As for what Steven said, the Mouse/Keyboard object can set the X and Y position of the mouse but this limits the movement of the new 'custom' pointer aswell, and causes it to spring back to the origin.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • don't get too excited, cuz it's only maybe, and as for when it wouldn't be too soon

    but keep an eye on construct discussion forum from time to time, because I was considering making a mouse plugin that can track mouse movement as separate from cursor movement

    it might also just be a part of the next custom controls plugin if and when that arrives

  • dammit overlooked another thing.................. AGGHH!

    yea sorry about that, i guess i should test things out before writing them, it was early in the morning and i hadnt though about the boundry and backlash that are causing these problems, heres a perfect version:

  • When I ran this Quazi, the sprite was constantly drifting left... also lost any ability to close it, I'm thankful for Alt+F4 haha

  • When I ran this Quazi, the sprite was constantly drifting left... also lost any ability to close it, I'm thankful for Alt+F4 haha

    it because of your version, i forgot about the changes to the window object, and it seems something is bugged about those changes with the windows x position in regards to the windows width, one thing fixed another kinda broken i guess.

    anyways, i fixed it so it SHOULD work in newer versions, just re-download it

    And alt-f4 or through the application itself is the only way it'll ever be closable, since your effectively highjacking the windows cursor

  • Still drifting, maybe my installation is screwed, somebody else should test it on v92

  • all i can think of too fix it now until the windowXY problem is solved is to disable caption in application properties.

    EDIT: seems to work fine for me in 99.92

    are you sure youre running the correct file/ did you redownload it?

  • Deleted and redownloaded again, same problem, but disabling the caption fixed it. No idea Hahaha

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