The Daily Click ::. Forums ::. Klik Coding Help ::. need help w/ platform game AI
 

Post Reply  Post Oekaki 
 

Posted By Message

NMasutaa



Registered
  26/12/2004
Points
  301
15th February, 2008 at 00:55:16 -

what's the best way to program AI for a platform game?

specifically, right now I'm wondering how to make an enemy that moves alternatively left and right on a platform, falls off the platform if it goes off the edge, and walks up and down sloped ground.

 
n/a

Ricky

loves Left For Dead 2

Registered
  28/12/2006
Points
  4175

Has Donated, Thank You!Game of the Week WinnerVIP MemberWii OwnerHero of TimeGOTM Winner! - November 2009I am an April Fool
15th February, 2008 at 01:06:20 -

I would like to see this as well. I have trouble with slopes.

Image Edited by the Author.

 
-

»xerus



Registered
  28/06/2002
Points
  675

You've Been Circy'd!Game of the Week Winner
15th February, 2008 at 01:44:09 -

I can give you some insight on the enemies from Bonesaw, I'm really tired but lets see...


You can make a platform engine based on moving each sprite around by 1 pixel in each direction, checking for a collision, and then moving it back to it's original position. You can then trigger flags for each collision direction, which your enemies and characters can use in later events.

So you need values like horizontal speed, vertical speed, and anything else you'll need for each object thats going to be in the platform engine. Then making enemies is as simple as making platform engine objects with self incrementing counters, and when the counter reaches certain values you can just tell the enemy to set its x speed to 2 or something to move right.

Thats all my brain can put out for now, hope I helped a little bit.

 
n/a

axel

Crazy?

Registered
  05/02/2005
Points
  4766

Game of the Week WinnerYou've Been Circy'd!
15th February, 2008 at 04:21:06 -

A lot of people seem to be having problems with doing platform movement AI, especially with multiple instances of an enemy moving around at the same time. So... I'm currently working on a small multi-enemy platform movement AI engine that I'll release as a public download as soon as I'm done with it. So, just be patient

 
n/a

AndyUK

Mascot Maniac

Registered
  01/08/2002
Points
  14586

Game of the Week WinnerSecond GOTW AwardHas Donated, Thank You!VIP Member
15th February, 2008 at 10:05:21 -

I do a bit of a sucky enemy ai in my lil pirate engine.

Each type of enemy has their own collision detector to fit their shape. It's quite high up so they can walk up less steep slopes. They just move up or down depending on if they are in the air or inside the floor (the events also work for solid active objects).

the collision event is something like

IF
detector1 overlapping background
+detector1 overlapping enemy1
+enemy1 flag 0 on (flag 0 is used to toggle left and right movement)

THEN
set enemy1 flag 0 off

and vice versa for going the other way.

 
.

AndyUK

Mascot Maniac

Registered
  01/08/2002
Points
  14586

Game of the Week WinnerSecond GOTW AwardHas Donated, Thank You!VIP Member
15th February, 2008 at 10:07:41 -

Image

so it would look like that ^

Image Edited by the Author.

 
.

Dustin Gunn

Gnarly Tubular Way Cool Awesome Groovy Mondo

Registered
  15/12/2004
Points
  2659

Game of the Week WinnerKlikCast StarVIP MemberI'm on a BoatGOTW Winner Oct 2010Kliktober Special Award Tag
15th February, 2008 at 13:37:38 -

I wouldn't recommend a detector, though it may seem simpler, connecting 2 objects together when there's more than one enemy isn't any more for beginners than doing it the proper way

This is certainly not for beginners either but I'll try to explain it in detail.

First, realize this checks every single pixel of movement, so if you're using fine detection and your enemy is animated, the pixels will go through the wall/floor and mess it up. You can practice with just having enemies as squares, but if you want to have fully animated enemies that don't require a detector, go into the animation editor and choose a direction you're not using, give it the exact same amount of frames, speeds, loops, etc as the real animations, and just make it a box.

Now at the top of all the events you have always - change ANIMATION direction (not change direction) to the box direction. Then you have all the platform AI events and collision tests, which will now test collisions for the box animation. After those, put an "always - restore animation direction" which if you changed animation direction earlier, will now revert to whatever you were using before, including being on the correct frame and everything. So it collides with the box direction and what you see is the drawn direction.

now the theory behind proper platform AI:

You can use fastloops or copy/pasted events over and over, but for each loop there should be:

* On loop "enemy move" If object's left speed is greater to loopindex("enemy move")
move object's x position to x position -1

* Is object over obstacle?
(perform slope test) set Y position to Y position -1
* Is it still over obstacle?
Set Y position to Y position +1, set X position to X position +1, set left speed to 0, whatever

Repeat that stuff for going right, and up and down (But with no slope testing for those 2, obviously)

I don't use 2 different values for left/right or up/down and instead have something like "X speed is less than (loopindex("enemy move")*-1)."

I also have a seperate routine for gravity which is similar in theory but pushes down only.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click