【GAMEMAKER】 follow player

Information about object: obj_player
Sprite: spr_player
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Step Event:
execute code:



///movement
if (keyboard_check(vk_left))  && !place_meeting(x-4,y,obj_obstacle)
{
    x-=4;
}
if (keyboard_check(vk_right))  && !place_meeting(x+4,y,obj_obstacle)
{
    x+=4;
}
if (keyboard_check(vk_up)) && !place_meeting(x,y-4,obj_obstacle)
{
    y-=4;
}
if (keyboard_check(vk_down))  && !place_meeting(x,y+4,obj_obstacle)
{
    y+=4;
}

Information about object: obj_obstacle
Sprite: spr_solid_base
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object

Information about object: obj_enemy
Sprite: spr_enemy
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

///Create Grid
size = 16;
grid = mp_grid_create(0,0,ceil(room_width/size),ceil(room_height/size),size,size);

///Add obstacles to grid
mp_grid_add_instances(grid,obj_obstacle,1);

//create initial path
path=path_add();

mp_grid_path(grid,path,x,y,obj_player.x,obj_player.y,1);
path_start(path,2,path_action_stop,true);
Step Event:
execute code:

///reset path at end
if path_position==1
{
    path_clear_points(path);
    mp_grid_path(grid,path,x,y,obj_player.x,obj_player.y,1);
    path_start(path,2,path_action_stop,true);
}
Draw Event:
execute code:

///For Drawing Grid
draw_path(path,x,y,true);
draw_self();

No comments:

Renowned Water Expert Reynold Aquino Offers Exclusive Water Softener Discounts

Los Angeles, California - November 21, 2024 - World-renowned water expert Reynold Aquino is excited to announce exclusive discounts on prem...

Contact Form

Name

Email *

Message *