I want to add AI cars and people to a driving game but I don’t know how. Can someone explain AI to me and some basic code for it?

Give me an example of what you know how to code already.

AI is a lot of fun. But there are two pieces to it,
First you have do clearly lay out in your mind (and on paper) what your ‘bot’ is going to do. This is difficult, because you have to think like a really really dumb robot. Its like writing a recipe, know that you have to explicitly specify what to do in every possible circumstance.
Second, you have to figure out how to code what you came up with in step one. If you know actionscript (or whatever language) already, then you are good to go. If you dont, then step two is just as hard as step one, and you are going to have to start small and build on it.

if your cars are flat images from the top and they dont even move yet, here is a start, using trigonometry to calculate the angle parts.

function onEnterFrame(){
this.angle +=(Math.random()-0.5) * spin;
var dx = Math.cos(this.angle) * speed;
var dy = Math.sin(this.angle) * speed;
this._x += dx;
this._y += dy;
this._rotation = this.angle/Math.pi*180;
This is untested, so the car probably will drive backwards or sideways, or spin the opposite direction its supposed to. Also you have to play with spin and speed.

A bot is a lot like an insect. A case machine :rd:. It does the same thing every time the same situation comes up (unless you use random();). So it’s basically made of “if”, and “else.” For example, if an ant sees a spider, it runs. If it sees a pea, it picks it up. If it sees a large food source, it calls upon other ants to help carry it back. It’s just extremely predictable cause and effect. Check out to see AI I made.

Haha. That game was great! And I’m guessing you found the distance between the car and people and if it was less than a certain #, you reversed their direction, right? And I wish that guy made the pathfinding AI tutorial. Thats what I was looking for.

Clownstaples: With that code, the object moves around erratically, and I was hoping for an object that just moves to spot after spot.