GameMaker Top-Down Enemy AI

C

CrackedGamer§

Guest
So, I am working on a Top-Down explorer game (is that a real genre?), I need some help with my enemy AI. Every enemy has the following states:
Idle - Wander randomly

Attack/Hunt - Run towards player while avoiding solid objects

Dead - Replace itself with a corpse

Cooldown - Stand completely still for 60 frames / 1 sec

The stuff that I have already gotten down is:

scr_enemyAttack
Code:
mp_potential_step(obj_player.x, obj_player.y, huntspd, false)
&

scr_enemyDie
Code:
instance_create_layer(x,y,"corpses",corpsetype);
instance_create_layer(x,y,"ui_invisible_objs",obj_enemy_loot);
instance_destroy(self);
The huntspd variable is set in the create event for the enemy, which in this case is: obj_player.movespd + 3

The corpsetype variable is also set in the enemy's create event, which in this case is: obj_medium_corpse

So the states that are left are:
Idle & Cooldown

I really have no idea how to do either of these efficiently, I could probably make a code for the Idle state with an alarm but I want to avoid that and keep everything (except setting variables, of course) in the step event so that everything can be in one script per state.

And I also want the enemy to detect the player if they are x amount of pixels away in front of them, my suggestion would be ray-casting but if you have a better idea go for it.

Also, I am not asking for anyone to write a script! But if you know of a function or technique that could be useful for this then please help me :)

--- THANK YOU IN ADVANCE ---
 
Last edited by a moderator:

Shavv

Member
Why don't you show first what you came up with and ask questions about that? You are basically asking for a service other then help with your problem.
 
F

Frozen Stick

Guest
This will take a while and as @Shavv stated , you are asking for service not a question.You should write your own code and we will help you if you can't get it working.
 

3dgeminis

Member
For distance use point_distance or distance_to_point
For attack/hunt, mp_potential_step
For dead, instance_destroy and instance_create
For cool down you can use an alrm or a variable timer=60; timer-=1; if timer=0 {........}
Check the MANUAL for more and look tutorials of Finite State Machine to program ai
 
C

CrackedGamer§

Guest
For distance use point_distance or distance_to_point
For attack/hunt, mp_potential_step
For dead, instance_destroy and instance_create
For cool down you can use an alrm or a variable timer=60; timer-=1; if timer=0 {........}
Check the MANUAL for more and look tutorials of Finite State Machine to program ai
Thank you, this will help immensely! :)
 
Top