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

Tracking mouse movement outside of game window

I

iambrettsoha

Guest
Hi all,

Experimenting with an unusual control scheme.

Player has two hands but only controls one at a time. They can alternate control with Right-click, while Left-click "grabs". If you switch control while grabbing, the hand retains its location.

These hands are controlled by the mouse movement, but in order to keep the hands locations independent from each other, I scrounged up some code to move the "active" hand by the relative mouse movement instead of just having it be 1 to 1 with the mouse coordinates. (sorry about that run-on sentence)

As far as I can tell, my code "works." But in order for it to pull together I need to be able to track the mouse's relative movement, even when outside of the game window.

Clamping the Mouse coordinates won't allow proper hand movement, and get_mouse_x() was also restrained to the game window's dimensions.

Here's a gif for some visuals

hands demo.gif


Here is the relevant code:

Step Event:

if (global.hand == "L")
{
if (grab = false || mouse_check_button(mb_left))
{
var diffx = mouse_x - premouse_x; //an artificial origin point is created each time the player switches hands
var diffy = mouse_y - premouse_y;
var x_ = pre_x + diffx; //the previous position of the hand is also stored in pre_x /pre_y whenever player switches
var y_ = pre_y + diffy;

x = lerp(x,x_,.3);
y = lerp(y,y_,.3);
}
}
else
{
x = x; //hand remains static when not selected, or when "grabbing"
y = y;
}


I appreciate any/all tips or suggestions
 
Not sure exactly what is going wrong, but have you tried the window_mouse_get_x() and window_mouse_get_y() functions? They should still return valid values outside of the game window (though they won't allow the mouse to "keep moving" past the border of the monitor like in a first person shooter, for example).
 
Top