Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Possible Duplicate:
New to creating AI - where to start?

I'm making a "Mario Like" game and I was wondering how would an AI generally work? I'm thinking of that it could just go to the player and fire whenever the player is x amount away from it but this is just confusing me. I'm not asking for anyone to write an AI, I'm asking about where to get started on building one or any experience you have with building an AI.

share|improve this question
1  
There was a post not long ago with various links to AI programming books. I am actually spewing that I didn't keep the link because there was some good material there. I'll try find it now –  Savlon Jan 28 '13 at 9:05
4  
Although this doesn't give you any code, it does give you a good idea on programming AI and the fundamentals gamedev.stackexchange.com/questions/2194/… –  Savlon Jan 28 '13 at 9:08
add comment

marked as duplicate by Byte56, Nicol Bolas, Laurent Couvidou, Trevor Powell, Tetrad Jan 30 '13 at 5:02

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

up vote 11 down vote accepted

Savlon already linked a great answer with several links in the comments.

However, for a simple Mario-like (hey!) platformer, I wouldn't worry too much about the AI.

In fact, you don't really need any real AI to create a nice and solid platformer (don't overcomplicate it!):

  • To avoid NPCs somehow dieing or wasting their "time" (or the system's processing power) before the player is there, only spawn them with the player being nearby. This way they don't have to determine whether the player is nearby, what they should do, etc.
  • Most classic enemy behavior can be realized using some very simple rules:
    • Let the enemy walk to the left. If he collides with something, he'll turn to the right.
    • If the enemy shouldn't fall off platforms (red turtle in classic Mario games), then check whether there is something walkable in front of them. If there isn't, change direction.
    • If the enemy should idle (piranha plants), just check how distant the player is. Don't leave the tube as long as he's closer than x units.
    • To decide which direction to shoot (hammer bros), just determine which the direction the player is.
    • Boss behavior can be controlled using similar logic combined with (pseudo) random numbers. Keep in mind that a big part of the gameplay for most platformers is the fact you'll have to find and remember patterns (e.g. when a boss jumps or when he shoots) to beat the game and not get hit. If you add AI, this won't necessarily become more challenging or interesting. It's more likely it gets too predictable or players will just aim for some loophole to get the AI into bugging out (not necessarily; but I consider this a great example why you won't need a full AI).
  • Classic consoles didn't have the processing power for real time AI decisions, as such this is really uncommon in this genre anyway. I'd say go with fixed/coded behaviors first and concentrate on gameplay. Later on, if you feel like it, you can extend this even more and in the end you'll essentially get an AI like behavior without writing explicit code for it.

Might be interesting to note:

The only AI involvement in a classic Mario-like platformer I know of is the approach to write a "jump and run solver" AI to essentially speed-run such a game (e.g. for Infinite Mario; more information can be found on MarioAi.org). So you're "programming" the player, not the enemies. Keep in mind that I'm not talking about something like the "guide mode" Nintendo introduced with the latest installments of the series. These are - as far as I know - just fixed instructions/scripts solving the levels in a very specific way (path, timing, etc.). Fun fact: With a real enemy AI using random decisions etc. something like that would be a lot more complicated to do (if possible at all, given limited resources and the player not wanting to wait).

share|improve this answer
    
+1 and I don't remember where I read it, but a lot of good games use that kind of implementation. Pac-man was praised for its ghosts "AI", but it doesn't have a real AI. I doubt that even some of Mario's enemies and bosses on wii games have any kind of non deterministic behavior. –  grprado Jan 28 '13 at 12:03
    
They don't, because their behavior is too simple (intentional). Even with an AI engine you wouldn't notice any difference. Closest to an "AI" would probably be the "Magikoopa" from Super Mario World, as they pick a pseudo random position where they appear, while being able to shoot the player, so there is essentially some decision making happening in background. But other than that, most enemies (in all games of the series) are either based on a few triggers or completely "dumb fire". –  Mario Jan 28 '13 at 19:49
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.