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

Legacy GM mouse circular movement problem

A

Amazing creature

Guest
Trying to make a different way of aiming

an object(clamp_range) moves around an object that's in the center of the view, when you move the mouse, "clamp_range" will move in a circular way, and like the mouse, it can't get closer or farther from the center of the view

ezgif.com-video-to-gif (1).gif

the problem I have is that when the view moves, the mouse also moves, and if I try to move it, it resets to the position the view had moved the mouse

ezgif.com-video-to-gif.gif

as you can see, the mouse moves alone out of the circumference, it refuses to move, and every time the view moves, the mouse gets farther until it's out of the screen

obj_center
end step
Code:
// half of the screen
offset_x = view_wview[0]/2
offset_y = view_hview[0]/2

x = view_xview[0]+offset_x;
y = view_yview[0]+offset_y
draw
Code:
draw_sprite(sprite_index,0,view_xview[0]+offset_x,view_yview[0]+offset_y)
clamp_range
step
Code:
if instance_exists(obj_center)
{
dir = point_direction(obj_center.x, obj_center.y, mouse_x, mouse_y);
dis = clamp(point_distance(obj_center.x, obj_center.y, mouse_x, mouse_y),99,100);

tar_x = obj_center.x + lengthdir_x(dis, dir);
tar_y = obj_center.y + lengthdir_y(dis, dir);

x = tar_x
y = tar_y

window_mouse_set(tar_x,tar_y)
}
 

Attachments

jo-thijs

Member
Trying to make a different way of aiming

an object(clamp_range) moves around an object that's in the center of the view, when you move the mouse, "clamp_range" will move in a circular way, and like the mouse, it can't get closer or farther from the center of the view

ezgif.com-video-to-gif (1).gif

the problem I have is that when the view moves, the mouse also moves, and if I try to move it, it resets to the position the view had moved the mouse

ezgif.com-video-to-gif.gif

as you can see, the mouse moves alone out of the circumference, it refuses to move, and every time the view moves, the mouse gets farther until it's out of the screen

obj_center
end step
Code:
// half of the screen
offset_x = view_wview[0]/2
offset_y = view_hview[0]/2

x = view_xview[0]+offset_x;
y = view_yview[0]+offset_y
draw
Code:
draw_sprite(sprite_index,0,view_xview[0]+offset_x,view_yview[0]+offset_y)
clamp_range
step
Code:
if instance_exists(obj_center)
{
dir = point_direction(obj_center.x, obj_center.y, mouse_x, mouse_y);
dis = clamp(point_distance(obj_center.x, obj_center.y, mouse_x, mouse_y),99,100);

tar_x = obj_center.x + lengthdir_x(dis, dir);
tar_y = obj_center.y + lengthdir_y(dis, dir);

x = tar_x
y = tar_y

window_mouse_set(tar_x,tar_y)
}
Have you already tried replacing:
Code:
window_mouse_set(tar_x,tar_y)
with something like:
Code:
window_mouse_set(tar_x - obj_center.x + obj_center.offset_x, tar_y - obj_center.y + obj_center.offset_y)
 
Top