Random speed (or equivilent)

Ok, I am working on this piece of flash:


now, what I want to do is have cars going along the roads at random speeds, or just travelling along the roads in random orders, whichever… anyways, as you can see, I am going to have a menu on the left hand side, which targets text into the scroll box on the right, and I want that to be able to happen without the movie re-starting everytime the cars finish going round, so the cars are going round and round in the background, and the layer on top is static. Will that happen automatically or not?

Basically i need to know how to do random speed or random intervals, and then the layer thing, if someone could lend a hand please :smiley:

Thanks, Pez.

Well, I HAD typed out the entire script to show you, but the textbox cleared out when I had pressed the back button. How lovely. I’ll repost the code later. I love EZBoard. Must remember to copy everything to clipboard before I preview. :mad:

Ok, thanks for when you get it done :slight_smile:

I got new hosting for my site…




here’s a starting place for you.

make a movie of a car, export it from the library as “car”, and delete it from the stage. then put this code in frame 1, it should only run once:

function makeCar(){
&nbsp &nbsp &nbsp &nbsp var mc = _root.attachMovie("car","car"+_root.count,_root.count);
&nbsp &nbsp &nbsp &nbsp mc.reset();
&nbsp &nbsp &nbsp &nbsp mc.onEnterFrame = mc.drive;

MovieClip.prototype.reset = function(){
&nbsp &nbsp &nbsp &nbsp this._x = 100;
&nbsp &nbsp &nbsp &nbsp this._y = random(100);
&nbsp &nbsp &nbsp &nbsp this.spd = random(18)+12;
&nbsp &nbsp &nbsp &nbsp this.limit = 300;

MovieClip.prototype.drive = function(){
&nbsp &nbsp &nbsp &nbsp if(this._x > this.limit) this.reset();
&nbsp &nbsp &nbsp &nbsp else this._x += this.spd;

count = 5;
&nbsp &nbsp &nbsp &nbsp makeCar();

the reset method is where you have most of your control. the _x is where the cars will start from, the limit is where they’ll go to before they reset, the _y defines a range possible vertical placement, the spd defines a range of possible speeds.

count is how many cars.

hmm, i notice on your site that you might want your cars to travel along a diagonal.

the script above could still be used as a starting place, but you’ll need some trig to get the diagonal thing happening. you might look at the random motion post and combine these scripts.

actually, it could be very similiar to the random motion, just with a fixed starting and ending point. or maybe choosing randomly from a series of fixed departure/destination pairs.

even more clever would be to have the cars turn at intersections.

good luck!

I will have a look and play with it, I am really desperate to get it to work :smiley: I have all of tomorrow to play, so wish me luck!