Advertisement

Side Scroller AI Take 2

Started by June 22, 2006 12:42 PM
1 comment, last by Red Ghost 18 years, 4 months ago
Hey everyone, I've been working on my side-scroller (think Battle Toads) off and on the past couple of weeks. I've been working on AI the past week. Pretty simple stuff really (Jump kick, punch etc) which as far as code looks, looks awful (trying to figure out how to make it look pretty :P). So my question is, right now I need to figure out how to make the enemy move to each side of the player. So basically (I'm at work now so I don't have access to my graphic utilities) I want something like this: The O's represent the enemy and the X represent the player. O X O Again, think teenage-mutant-ninja turtles. I only want at most two enemies to attack the player at one time (or rather two enemies to be next to the player at one time). So that brings about two things (one really isn't AI related but)... In my player class I thought I'd have two variables that are essentially "slots" that hold the enemies that are currently next to the player. I thought this worked well, but soon realized that I would have to have the enemy update the slot when it died or when it was too far away from the player. This meant I'd have to choose a distance. While this works I still wonder if there is a "better" way. Now onto the main AI question. This is going to be interesting to explain (might have to make diagrams later). If I have a player fighting with an enemy like this: X O O <-- enemy wants to fight player on other side! How do I get the player to go to the other side? I guess I could use some sort of goTo point command, however the entities playing field is not grid based, it is free-formed. So how do I get the enemy to go around the other enemy and, even more important, go to the other side of the player to attack him/her!? Another question pertaining to this is what if the player is backed up against the wall and the player is fighting an enemy. How will another enemy know that it can't attack the player (since he/she is backed up against the wall). Thanks for your help, and I know it might be hard to follow, I'll try to get some diagrams up in 5 or 6 hours but I wanted to get the ideas flowing :) P.S For classes I have the following: Entity Player -> Inherits from Entity Enemy -> Inherits from Entity
Enemy train of thought:

1. Am I touching player?
2. If yes, attack player. Goto 1
3. Am I touching another enemy?
4. If no, walk towards player. Goto 1
5. Can I jump over player?
6. If yes, jump over player. Goto 1.
7. Else. Do nothing. Goto 1.
Advertisement
Hi,
Your slot idea is nice. Why should the enemy update the player slot ?
Wouldn't it be better to have the player object check its slots ?

I guess your player object already does some collision detection to check wether it is bumping into something or not.

If live enemy or wall within slot1 area, set slot1_used to true
else set slot1_used to false
If live enemy or wall within slot2 area, set slot2_used to true
else set slot2_used to false

Then the enemy train of thought is just modified to request the player for a free slot:
1- am I touching the player ?
2- attack player. Goto 1 else goto 3
3- request player for free slot
4- if free slot
5- walk to free slot. Goto 1 else Goto 8
6- can I jump over player ?
7- jump over player and got to free slot. goto 1
8- Do nothing. Goto 1

The idea is to use the player collision detection function to detect wether its slots are available or not.

Hope that helps.
Ghostly yours,
Red.
Ghostly yours,Red.

This topic is closed to new replies.

Advertisement