It's just a jump to the left...

Posted by Carnivac on Aug. 21, 2008, 5:18 p.m.

Just typing this to get some thoughts out of my head. Am currently adding some various kinds of enemies into my game and got to thinking about the different types of 'AI'. Now I'm not an expert coder so truly smart enemies that don't get caught behind walls (and suck up all the CPU when there are loads on screen) and it seems a lot of classic 2D games don't even have anything even resembling intelligent enemies. They march along from the right to the left and usually turn back if there was an obstruction but most of the time they don't really care about you being there at all. They're more like obstacles than true threats and rather than actively harrass you and try to hit you they just seem to hurt or kill you simply if you happen to accidentally touch them. This seems to be the most common type of enemy behavior though often you might have a 'sentry' kind of thing like a fixed gun turret (or a soldier who never moves) who will occasionally fire in your direction though again these often seem to be automated and have a set time between each shot (where you'd likely jump or crouch to avoid the bullet and edge your way to destroy the annoying gun).

You will occasionally get an enemy type who feeeels like he's after you (like Lakitu in Super Mario Bros who seems like he's tormenting you through the whole level keeping up with you and throwing down the spikey things) but again he didn't require any specific pathfinding and stayed pretty much on the same vertical plane at all times.

When I first tried to code enemy behavior it was for an enemy that was basically a 'reskin' of the player character. Suit looked different and all that but it was to still fly about, and shoot with all the bits in the same place, and act like the player in that it would navigate even the twisty turny thin passages to hunt you down. I realised that was a lil beyond me and though I got it sorta working (though getting stuck behind walls at certain points despite making waypoints) it didn't feel quite right. It didn't feel all that fun. Not sure why that was. I coded a simpler enemy who crouched when you crouched and jumped when you jumped so it was always on the right level to shoot you but it made the game far, far too annoying. But here I am coding very simple enemies who just go about their business and there are lots on screen and somehow it does feel fun, especially the mass amount of carnage when shooting them all in quick succession. Now I've added it where someone of them do indeed check if you're in their line of fire and shoot at you a few times and then go back to their pre-planned route. Again for some reason it just feels right just having the enemies feel even just 'alive' and moving about rather than 'intelligent'.

I think what I may do is have a couple of the 'seeker' enemy types restricted to the more emptier wider spacous rooms (nothing kills that supposed intelligence more than watching them trying to walk through a wall to get to you) and keep the sentry/patrol types to the more complex rooms with the thin passages and twists and turns. Least then there's a bit of variety too depending on the room.

Anyways sorry for babbling on about this crap. Does help getting it out of my noisy mind and in a readable form though. Just feels to me that having supposedly smarter enemies doesn't mean the game's gonna be that much more fun. Maybe it's cos I'm not a PC gamer as such and I don't care for all those FPS games where the enemy AI needs to be great else it ruins the 'realism'. I dunno. As long as the game is fun and challenging I don't think it matters.

Christ I write some shite…

Comments

PY 15 years, 8 months ago

Ai is my weak point.

Leper-Messiah 15 years, 8 months ago

And a step to the left.

I love The Rocky Horror Picture Show :D

AI is hard =[

Austin 15 years, 8 months ago

Quote:
And a step to the left.
It is to the right… lrn2timewarpagain

panzercretin 15 years, 8 months ago

A good idea would be to create a "seeker" ai, and when in range to the player, it creates a "sight" sorta object that stretches from the enemy to the player. If this object comes in collision with a wall, then the object is destroyed, the ai ignores the player and goes back to its random walking about.

Although, creating AI for a "linear" platformer game, in which the only movement options are left or right, are much simpler. Because walls don't appear much in this type because there is no way to go over them, the aggressive AI can simply move to the right when to your left, and vice-versa. Passive/"civilian" AI simply wander about, side-to-side. A "sentry" type would be useless, because it needs only to shoot horizontally to bag a kill. But then, what happens to AI that shoot? That's all they do: simply shoot. If they shoot randomly left or right, there is a 50/50 chance of it hitting the target, because it is all in one plane. With a small amount of coding, however, it can shoot where you are.

How do you deal with that to avoid it? You can either make the player shoot, too, or skip the idea of shooting entirely, which makes more sense.

Then again, from the looks of your banner, you prefer working on Platformer or Overhead games, the two more orthodox 2-D gametypes. I'd go further into that, but I simply make "seeker" ai, which works anyway for most shooters.

The best option is to make a 2-player offline game, because there is absolutely no need to code ai, except perhaps for certain weapons, which are easy to code anyway. 2-player games are by far the simplest to code ai for, are usually simple(because in order to avoid keyboard-crowding, one player usually can only use 2-6 buttons), modes are simple to create, and are fun for when a friend is over. The only downside is, if you don't have a friend(or at least, not one nearby), your game doesn't work well.

Another idea is to make a simple game anyway, in which ai are either extremely simple or non-existent, like an arcade-ish game.

Take pong, for example. All the oppoent's paddle has to do is simply follow the y coordinate at a certain speed, but not pitch perfect, so that it's beatable.

Simpler arcade games like that are easy to code ai for, and in the form of a collaboration of many of them, can be extremely fun. So, a good concept would be to make a collaboration of 30-50 simple games you have made, make a gauntlet of randomly-chosen games, and perhaps make a 2-player mode with alternate games.

Then again, I think this comment is longer than your whole blog.

V 15 years, 8 months ago

AI is one of the most challenging parts of creating a game, and based on what you want it to do, will make it more compicated. I've never had much trouble making something like a decent AI, but it just depends on who's doing it. AI just happens to be one of my strong suits, making graphics isn't. XD

Broxter 15 years, 8 months ago

Is this the 'Longest Post' competition?

F1ak3r 15 years, 8 months ago

Regarding Twinsoul's post, this is 2008, we don't need sight objects because we've got collision_line().

Quote:
nothing kills that supposed intelligence more than watching them try to walk through a wall to get you.
Simple fix. Make all the enemies ghosts. =)

SixWinged 15 years, 8 months ago

Quote:
Ai is my weak point.
AI is EVERYBODY's weak point.

Cesar 15 years, 8 months ago

Broxter, if you were here when she-who-shall-not-be-named was here, you'd see that every single post on her contreversial entry was entry-worthy as well.

I'd actually like a turret enemy like those in banjo tooie, they actually shoot IN FRONT of you. It was a bitch but it was awesome since dodging required you to, get this, NOT RUN STRAIGHT.

Now imagine that with a lot of bullets. At once. It shouldn't be too hard to calculate where the player SHOULD be using his/her current velocity, direction, and taking gravity into the equation.

Then again, I remember very little of when I was on gamemaker.

Cesque 15 years, 8 months ago

First of all: I just now checked your site, and, wow. Can't wait to play some of these.

Second of all: AI is pretty much my weak point, too, but I'm making progress ;) My favourite variation of the "sentry" type enemy is an enemy that goes right/left depending on where the player is (a bit like what Twinsoul mentioned), but only checks which way to go every X steps, that is, it doesn't just gets stuck in the player, but rather runs back and forth "through" them. Better than nothing or the sentry type. :P

Lately, for more intelligent enemies, my way of working (also recommended for those interested) is to use Game Maker's "miscellaneous event" conditions for things like: Attack 1, Attack 2, Jump, etc. irst I test the enemy's action by making tit execute particular event on demand, and then, I code the AI in to execute particular actions in particular cases - eg. jumping when the enemy gets to an obstacle and the player is behind.

The general good idea is to make enemies try and correspond to what the player can do and would do… especially for human-esque enemies. If an enemy has a ranged attack, it would probably make more sense for "intelligent" enemies to try and keep distance from the player, rather than charging in at all times.