Random Movement

I’ve seen the tutorial for the random movement in flash mx but i’ve bee having some problems. How do you make it so that it starts where you want it. Ex. after i set the coordinates and I test the movie it will slide somewhere(at random) then start sliding only in the set parimaters. I’m not sure if you understand that but plz could someone help me?

I’ve tried so much flipping things around in the actionscript and a whole bunch of other crap. plz help

If you’re using the MX version of the tut, then the MCs will start where you place them on the stage.

I don’t know what you mean about the range thing. If you mean you want the MC to start in a specific place, then move to a random location, then move back and forth between those two points, you’ll need different code.

well the problem is. it starts out where i put it then it moves to a random location far away. then it start moving around but only in the range i set it in. like i set it in say:10 by 10. it would start out where i put it, the it would slide to an area, then it would start moving randomly staying inside a 10 by 10 frame. it’s like it starts doing the 10by10 stuff after it does a random start point. i dno i’m confused too.

Here’s a way to kinda cheat it :P. With Suprabeener’s code, you can easily change the range of them ALL because that’s how a prototype code works. One code works them all. Instead of playing with that code, I did something different. Make a bunch of movieClips and apply this to all of them:


onClipEvent(load){
	oldx = this._x;
	oldy = this._y;
	speed = 5;
	_root.asdf = oldx;
}
onClipEvent(enterFrame){
	if(getTimer() > oldtimer){
		oldtimer = getTimer() + 1000;
		targetx = (oldx - 10)+Math.random()*(oldx/2);
		targety = (oldy - 10)+Math.random()*(oldy/2);
//chage the 2 in oldx/2 and oldy/2 to shorten the range of
//movement.  The higher the number, the smaller the area
	}
	distancex=targetx-this._x;
	distancey=targety-this._y;
	_x+=distancex/speed;
	_y+=distancey/speed;
}

If you don’t know, the random number generator works like this:
10+Math.random()*20;
The first numbers the lowest number, the highest random number this will generate is the sum of both numbers (ie 30). So, I took the MC’s individual old coords and it works around that. If you want the reduce the range, reduce the last number. Hope that helps!!

yeah thanks man although i havn’t tried it out i’m sure it works lolz. thanks anyway. i’m not sure y no one else answered to this:S