LoginLogin

Enemy ai

Root / Programming Questions / [.]

KomodoCreated:
so i'm in progress of making a top down rpg and I need some help on enemy ai so if you guys can give me some ideas that whould be great thanks.

Random moving enemies or 'smart' ones? If it's random then one (bad) way to do it could be
R=RND(4)
IF R AND 1 THEN INC X 'movement code like X=X+1
IF R AND 2 THEN DEC X
IF R AND 3 THEN INC Y
IF R AND 4 THEN DEC Y 
or something of that sort. Smart enemies are harder.

smart enemys that attack with a sword when close enough.

Enemies in the NES era traditionally had very basic AI, take for example The Legend of Zelda. Every single enemy had either very linear AI (e.g. move towards player at constant speed) or random AI (e.g. move randomly and change direction every x frames), or some combination of the two (e.g. appear in a random spot and fire towards the player, then disappear). These things are quite easy to program to be honest, and depending on your game, are likely to be very fun to play against. If you strive for more advanced AI, there is no one right way to do it. You seem to know what you want the enemy to do (get close to play, attack with sword), it's not so hard to code. Code it, see how it behaves, then think about ways to improve it - or maybe you'll think that it's fine the way it turns out!

ok i think i got a basic idea of what to do ,but how do you change the speed the enemy is going because i run into a problem of it going way to fast making it difficult to beat.

You change the speed by changing how far the enemy travels in a fixed amount of time.

What you'll want is for the enemy to home in on the player at a certain range, yes? You will need to have either a sight collide box or a presence like collide box on the player. When whichever connects, have it home in on the player. The method for something like that, which does it most well is the "A* path finding algorithm". Something I hope someone else will elaborate on because I currently have no clue how to implement one yet, ha. Trying to understand it myself.

so i need to make a collision box around the character using somthing like sphitsp and every time the enemy hits it he attacks with the sword hmm i think i like that idea(you know three weeks ago i whould have had no idea how to do that but now i do) i think i will also for harder enemys make a projectile like a knife or arrow fly at the charecter if they are on the same x mark or y mark if you know what i mean but first i will give the player a shield so it's not to difficult. I have a plan now thanks guys for your ideas you are a huge help.

Yeah, I haven't done it myself but I believe you could use a transparent sprite box around the character, and use that for detection range.

my enemy ai is almost ready to be put in my game! i just have to fix some things. thanks guys for your ideas i realy appreciate it. good luck with your programming.

You could make an enemy that moves randomly until you get within it's range. For example:
IF PLAYERX>ENEMYX-50 THEN ENEMYX=ENEMYX+1
This but with all the rest of the directions. Add something like Minxrod's thing for random.

Guzzler's idea is better than mine if you want something simple, many older games with which SmileBASIC has based itself all have some pretty simple enemies. The one he is suggesting here would home in on the player.