artificial intelligence
Moderator: Moderators
-
- Posts: 3140
- Joined: Wed May 19, 2010 6:12 pm
artificial intelligence
Does anybody have an idea how the enemy AI works in a game like Gunstar Heroes? I tried programming it earlier today, but I realized that it was more difficult than I thought it would be.
Re: artificial intelligence
Lots and lots of conditionals, random numbers when there's more than one option. I think enemy AI is simple to understand, just hard to do well.
Stuff like
This would try to throw a player if the player is close enough to be thrown. If the player is not close enough to be throw, it would randomly either shoot at the player, or move the enemy toward the player. If you want smarter AI, you need more conditionals.
For instance, I might have a state for shooting, because it'd be weird if the player moves toward the player half the time, and shoot them half the time.
Like... move a pixel, shoot one bullet, move a pixel shoot one bullet. So I'd have it choose to enter a shooting stance for a few frames so it doesn't look as choppy.
It's just a lot of conditionals until it appears smart.
Stuff like
Code: Select all
if(playhorizontaldistance < grabrange){
attempttothrowplayer();
}else{
if(getrandomnumber()%2){
isplayeronright(){
moveenemyright();
}else{
moveenemyleft();
}
}else{
shootplayer();
}
}
For instance, I might have a state for shooting, because it'd be weird if the player moves toward the player half the time, and shoot them half the time.
Like... move a pixel, shoot one bullet, move a pixel shoot one bullet. So I'd have it choose to enter a shooting stance for a few frames so it doesn't look as choppy.
It's just a lot of conditionals until it appears smart.
Re: artificial intelligence
Most enemies are way more powerful than the player, so that their AI doesn't have to be very smart. Only in games where the enemy has the same abilities as the player is the AI smart, though still it has the advantage of superhuman speed, instant perception of player actions, and instant decision making.
Re: artificial intelligence
In many games the AI is acting too stupid though. Such as in Pokemon Card GB2, often the opponents will draw way too many cards.
In a slow computer such as Famicom, you might calculate some decisions ahead of time too during the loops doing other stuff, if it does not have to act right away, but such things may be more difficult to program.
In a slow computer such as Famicom, you might calculate some decisions ahead of time too during the loops doing other stuff, if it does not have to act right away, but such things may be more difficult to program.
(Free Hero Mesh - FOSS puzzle game engine)