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

GameMaker help with enemy attack state!!

E

Elkrom

Guest
having multiple issues with this code, at first glance when i started the room it seemed like it was working until i realized that if i was to the left of the enemy they would run away from me rather than at me , and if i came in contact with the enemy i got this fatal error. "unable to find any instances for object index '0' name 'obj_player' ..... dir = sign(obj_player.x - x);" and its weird when i just have it written as dir = sign(obj_player - x) i do not get this error. if anyone can give any insight i would be much appreciated and also if anyone could help with making the enemy look towards the direction its moving that would be awesome too ive tried for the last couple days but cant seem to make it work. also might be worth noting this is from the shaun spaulding enemy chase AI tutorial video.








case e_state.chase:
{




dir = sign(obj_player.x - x);
hsp = dir * 2;
vsp = vsp + grav;
sprite_index = spr_slimeAttack
if (abs(obj_player.x-x)<1) { hsp = 0; }
if (distance_to_object(obj_player) > 128) state = e_state.idle;




// Animate / character flip where pointing


}
break;
}
 

johnwo

Member
Is there an instance of obj_player in the room?
obj_player - x won't throw an error as obj_player is an object_index, which is a number (real).
 

johnwo

Member
unable to find any instances for object index '0' name 'obj_player'
It was a rethorical question, as the error states that there is not an instance of obj_player in the room.

You can confirm this in code.
Paste the code below in the e_state.chase case in the switch.
Code:
if (!instance_exists(obj_player)) game_end();
If the game ends, then there isn't an instance of obj_player...
 
E

Elkrom

Guest
i did fix the image_xscale issue tho just did, If (dir != 0) image_xscale = dir;
 

TheouAegis

Member
The fatal error to me sounds like you are killing the player as soon as it comes into contact with the enemy and so the enemy is looking for the player which is already been destroyed, so error!
 
Top