Skip to main content
GameDev.net gamedev.net
🔒 Locked

Beginner with AI needs help

Started by Ostridge Mar 6, 2009 at 3:20 PM 0 replies 1k views
Original Post
Ostridge
Ostridge
Hi everyone. I have an RPG game that i am currently working on. You can run around the world and fight enemies. I am not sure how you make any kind of AI. What i do as of right now to get my enemies to attack me, is just generate a random number and then each number specifies some action. i.e if the number is 1 he will regular attack me, if its 2 he will cast a spell etc. I dont really need any complex AI for my monsters, but i would like them to actually make moves based on whats happening. For instance if they can heal themselves i would like them to heal when they are getting close to dying. I am also working with C#. Could someone point me in the right direction or help me out with getting my enemies to fight better? Thanks in advanced!
remigius
remigius

Well, instead of generating a random number, you could do some simple AI with just a few if statements. Assuming you have some class set up for your enemy NPC objects, you could for example do something like this in their update loop:

// when we're low on healthif (this.currentHealth < this.someHealthReserve){   // heal ourselves   this.DoHeal();}// if we're vastly overpoweredelse if (player.characterLevel - this.characterLevel > 5){   this.DoFlee();}else{   // you can still generate your random attacks here}


For simple AI, this should work out fine, but you might want to incorporate some timeout for these checks if you want certain actions to take a while (for example to play some animation). If you find the if/else list growing too unwieldly, you might want to check out some more flexible AI techniques. I was quite happy with a simple automaton approach I used in a little game of mine.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.