Program Enemy “Floating” AI

AIGame Maker Studio 2Gameplay Tutorials

This week I want to show you a fun bundle of code to make some floating AI with GameMaker. (To all my Construct peeps, when the new site goes live the content will be split for both GameMaker & Construct!)

Let’s make an enemy sprite like this:

This gives us two frames, and while my animation isn’t going to win me any awards, the background getting lighter in the second frame will at least give some illusion of floating.

Then in the create event for the enemy (ob_enemy) we control the frame speed like so:

 image_speed = 0.4; 

Now we need to make it float towards the player object (go ahead and make a placeholder ob_player):

Let’s examine this crazy line of code:

 y += motion_add(point_direction(x,y,ob_player.x,ob_player.y)+8+random(32)-16,0.1+random(0.4)-0.2);

 if speed > 2.5 { speed = 2 } 

Our end result should net us something like this: