Limiting cursor range with gamepad right stick

S

Smidger

Guest
Hi everyone,

I've looked over many GML scripts and suggestions from the generous community here, but haven't found one that helps me to limit the range of my cursor aim object in a twin stick shooter. It basically means that at present, the cursor object can be at the far end of the viewport, which makes it difficult to quickly alter the direction.

I have the following code, which seems to be working pretty well, but I'd like the cursor to be closer to the player for quick direction changes. If anyone knows of a way to set the range as a radius value around the player, that would be most appreciated.

//STEP EVENT for o_player

scrollSpeed = 30;

if (gamepad_is_connected(0))
{

if ((gamepad_axis_value(0,gp_axisrh) >= 0.5) || (gamepad_axis_value(0,gp_axisrv) >= 0.5)
|| (gamepad_axis_value(0,gp_axisrh) <= -0.5) || (gamepad_axis_value(0,gp_axisrv) <= -0.5))
{

input_h = gamepad_axis_value(0,gp_axisrh);
input_v = gamepad_axis_value(0,gp_axisrv);
cursor_x = window_mouse_get_x() + input_h * scrollSpeed;
cursor_y = window_mouse_get_y() + input_v * scrollSpeed;
window_mouse_set(cursor_x, cursor_y);
}
}
 

TheouAegis

Member
You can set thresholds so that anything less than 0.5 will be ignored.

will the cursor just be going around the player in a circle or will it be able to go toward and away from the player? If it will stay at a constant range away from the player, you could actually just simply multiply the values of the axes by the distance you want the crosshair to remain away from the player and then add those values to the players coordinates.
 
S

Smidger

Guest
You can set thresholds so that anything less than 0.5 will be ignored.

will the cursor just be going around the player in a circle or will it be able to go toward and away from the player? If it will stay at a constant range away from the player, you could actually just simply multiply the values of the axes by the distance you want the crosshair to remain away from the player and then add those values to the players coordinates.
Hi TheouAegis,

Many thanks for the reply. I was thinking that the cursor should be able to go toward and away from the player, which would match my current keyboard and mouse controls for the game. I've some video examples of the game on Instagram. https://www.instagram.com/p/BqP9B4lF9jA/
 
Top