2d Platform game AI

Does anyone know how to go about doing a 2d Platform game Enemy AI? Think of Super Mario Brothers 2 or 3 for the Nes. Character walking to the left and right and when it gets to a certain point it attacks the player taking some life away or totaly killing it.

That’s not something that could be briefly described really. To be general and not provide an actual script for you though: What I’ve done is create a trigger with the script attached and then use raycasts to find if it is grounded or if it is touching a wall, and then have it move around accordingly based on the movement type I want for it, such as jumping or slowly moving.

I have a variable called “state” that tells the Update function what kind of behavior it should be following. Every second I check the distance to the player, and if it is close enough then I change it to an aggressive state instead of the normal walking around state, and then had corresponding code for each state within their own “if (thisState == true)” block.

I wanted some randomness and unpredictability so I created a random timer that gets reset at every state update, so every say 1 to 3 seconds it will re-decide what it wants to do from a list of possible actions, like walk forwards, jump back, lunge and attack, get in close and attack quickly, etc.

You really have to understand the logic behind programming and then think: “What do I want my enemy to do and in what situations should it change?” and then just work out how you’re going to do it.

Sounds really cool any ideas where to point me for a example of this type of thing? Thanks for the help.