The wonderfully frustrating fun of AI

Yes, that’s right. Now that my game has a gui and a player and that junk, the next thing is AI. And before you flame me for asking, yes I did search the forum and the only response anybody gets is: AI is a very broad subject, and you’ll need python to programme it. As useful as this is, it doesn’t exactly help the poor noob who doesn’t get it. So I’ll de-broadify AI into what I think I need. All the enemy needs to do is chase the player if you’re close to it. Attack you if you’re even closer, and die if it runs out of health. I tried this simple approach, but, just as I suspected, it didn’t work. And not to mention, when I duplicated the enemy, all the pretty strings in its logic setup disappeared. So now I appeal to you, the guys who know how it’s done, can’t somebody please tell me how I can create an efficient, simple AI like the above described which isn’t torn to shreds when the enemy is duplicated?! Thanks in advance.

Here’s some pseudocode for what you need:

get sensors and stuff
def distance(ob1,ob2):
  p1 = ob1.getPosition()
  p2 = ob2.getPosition()
  a = abs(p1[0]-p2[0])
  b = abs(p1[1]-p2[2])
  c = abs(p1[2]-p2[2])
  d = sqrt(a*a+b*b+c*c)
  return d
if distance(own,player) < 10:
  own.state = "aiming"
elif distance(own,player) < 5:
  own.state = "attacking"
if hit.isPositive(): -= hit.damage
if <= 0:
  own.state = "pushingupthedaisies"

In other places in the script you’d have things that correspond to each own.state, such as walking when “okay”.

Oh yeah: Moveforwards is a Motion actuator, Tracktoplayer is an Edit Object (Track To) actuator, and the player’s attacks must have the property damage as an int. Plus the enemy needs the property health as an int.

Hello Dakka

I was looking at the same thing this weekend and had a look at Social’s tutorials which used some perfectly formed python to run them. Then I realised I could do the same with logic bricks. so here is my rather crap noob offering… but it shows what I was doing.
the player can fire with the Ctrl key and manouver with the arrow keys, the enemy will track and follow you when you are within range and shoot when you are closer. I’m sure you could make it die if you want to with end object. Oh and nothing actually dies here, it just fills the world with balls

Lol. Looks like peas vs corn.

Thanks for the help. The following bit I could easily get, but I wanted the enemy to only be able to hurt the player if coliding with the player, and if the enemy has a bool function called attack set to true, and finally, if the enemy has another bool function called front as true (to mke sure the enemy can’t attack when you’re behind it.