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

Having Enemy Problems

7

7Left

Guest
So we are having a problem here at 7Left where the enemy wont get close to the player and it flickers about and teleports around the player. This is our first fully fledged game so we dont know much about coding. We will upload the code

Enemy Step event:

if (instance_exists(player_obj)) move_towards_point(player_obj.x,player_obj.y,spd)
image_angle = direction
if (hp <= 0) instance_destroy()

Enemy Create event:

hp = 1;
spd = 15;

Enemy Collision w/ Player event:

game_restart()

Barrier Collision w/ Enemy event:

with(other)
{
hp = hp - 1

}

Player Create event:

//Creation Barrier
if(keyboard_check_released(vk_nokey))
{
instance_create_layer(x,y,layer,Barriar_Pje)
}
//Health
hp = 1

Player Step event:

//Movement
if (keyboard_check(vk_right)) x=x+7;
if (keyboard_check(vk_left)) x=x-7;
if (keyboard_check(vk_up)) y=y-7;
if (keyboard_check(vk_down)) y=y+7;
image_angle = point_direction(x,y,mouse_x,mouse_y);

Player Key Down event:

//Barriar
if (keyboard_check_pressed(vk_anykey))
{
instance_destroy(Barriar_Pje)

}

Player Key Up event:

//Barrier
if (keyboard_check(vk_nokey))
{
instance_create_layer(x,y,layer,Barriar_Pje)

}


If anyone could tell us what we have wrong here then we would be extremely appreciative
 

Carolusclen

Member
Usually this happens when you have code yo move the enemy to the player but nothing to stop the enemy once it reaches there :)
 

Simon Gust

Member
What can happen is that if the enemy is 10 pixels away from the player but their spd variable is 20 for exmaple, the enemy will indefinetly overshoot the player.
You can do this for example:
Code:
if (instance_exists(player_obj))
{
   var dis = point_distance(x, y, player_obj.x, player_obj.y);
   move_towards_point(player_obj.x, player_obj.y, min(dis, spd));
}
 
7

7Left

Guest
What can happen is that if the enemy is 10 pixels away from the player but their spd variable is 20 for exmaple, the enemy will indefinetly overshoot the player.
You can do this for example:
Code:
if (instance_exists(player_obj))
{
   var dis = point_distance(x, y, player_obj.x, player_obj.y);
   move_towards_point(player_obj.x, player_obj.y, min(dis, spd));
}
I tried it and it fixed the flickering but it still teleports about and won't get closer to the player

this is a screenshot of me pressing no buttons. the enemy hasnt moved since I stopped and when I move it teleports around me
 

Attachments

Top