JEMcG
Member
Hi,
I've been making a click to move system (that works alongside keyboard movement), which works other than one irritating bug.
When I click a path is made and I use mp_grid_path to move the character.
I've linked this to the animation system. When the character reaches their destination, this deletes the path and resets the variables, stopping the character.
This works just fine unless I click a second time.
This uses the same variable/path (wpath) though I have set it to delete on click to stop several paths being generated.
This does not seem to work and if the mouse is clicked prior to reaching the end of the path, nothing resets and the player continues to animate.
Wondered if anyone could help as to why?
(hInput & vInput are from the keyboard movement and the script "space_check" just finds the nearest free space in the event of a collision.)
Thanks!
STEP EVENT:
//Mouse Movement
if(mouse_check_button_pressed(mb_left)){
//wipe previous path
if(path_exists(wpath)){
path_delete(wpath);
}
finalx = -1;
finaly = -1;
onpath = false;
wpath = -1;
//Get mouse location
var mx = mouse_x;
var my = mouse_y;
//Is this on a collision?
if(position_meeting(mx, my, obj_col)){
var newsp = space_check(mx, my);
//change mx/y to new location
mx = newsp[0];
my = newsp[1];
}
//move to mx/my
wpath = path_add();
mp_grid_path(global.mgrid, wpath, x, y, mx, my, false);
path_start(wpath, spd, path_action_stop, false);
finalx = mx;
finaly = my;
onpath = true;
}
//---Animations
//turn off anim
if((x == finalx) and (y == finaly)){
path_delete(wpath);
finalx = -1;
finaly = -1;
onpath = false;
wpath = -1;
}
//get Direction info for anim
if(onpath){
dir = direction;
}
DRAW EVENT:
//Work out anim frame
if(hInput != 0 or vInput != 0 or onpath){
y_frame = floor(dir/45);
//Increment frame for animation (if we make an idle anim take this out of IF)
x_frame += anim_speed/room_speed;
if(x_frame >= anim_length) x_frame = 0;
} else {
x_frame = 0.9;
}
var xx = x-x_offset;
var yy = y-y_offset;
//Draw Sprite
draw_sprite_part(spr_mc, 0, floor(x_frame)*frame_width, y_frame*frame_height, frame_width, frame_height, xx, yy);
I've been making a click to move system (that works alongside keyboard movement), which works other than one irritating bug.
When I click a path is made and I use mp_grid_path to move the character.
I've linked this to the animation system. When the character reaches their destination, this deletes the path and resets the variables, stopping the character.
This works just fine unless I click a second time.
This uses the same variable/path (wpath) though I have set it to delete on click to stop several paths being generated.
This does not seem to work and if the mouse is clicked prior to reaching the end of the path, nothing resets and the player continues to animate.
Wondered if anyone could help as to why?
(hInput & vInput are from the keyboard movement and the script "space_check" just finds the nearest free space in the event of a collision.)
Thanks!
STEP EVENT:
//Mouse Movement
if(mouse_check_button_pressed(mb_left)){
//wipe previous path
if(path_exists(wpath)){
path_delete(wpath);
}
finalx = -1;
finaly = -1;
onpath = false;
wpath = -1;
//Get mouse location
var mx = mouse_x;
var my = mouse_y;
//Is this on a collision?
if(position_meeting(mx, my, obj_col)){
var newsp = space_check(mx, my);
//change mx/y to new location
mx = newsp[0];
my = newsp[1];
}
//move to mx/my
wpath = path_add();
mp_grid_path(global.mgrid, wpath, x, y, mx, my, false);
path_start(wpath, spd, path_action_stop, false);
finalx = mx;
finaly = my;
onpath = true;
}
//---Animations
//turn off anim
if((x == finalx) and (y == finaly)){
path_delete(wpath);
finalx = -1;
finaly = -1;
onpath = false;
wpath = -1;
}
//get Direction info for anim
if(onpath){
dir = direction;
}
DRAW EVENT:
//Work out anim frame
if(hInput != 0 or vInput != 0 or onpath){
y_frame = floor(dir/45);
//Increment frame for animation (if we make an idle anim take this out of IF)
x_frame += anim_speed/room_speed;
if(x_frame >= anim_length) x_frame = 0;
} else {
x_frame = 0.9;
}
var xx = x-x_offset;
var yy = y-y_offset;
//Draw Sprite
draw_sprite_part(spr_mc, 0, floor(x_frame)*frame_width, y_frame*frame_height, frame_width, frame_height, xx, yy);