Hello,
I’m using this code found on this site for random motion. I have about 40 spheres that I’ve attached it to. The problem I’m having is I can never get all the spheres to move…usually one to three of them just sit still. And since it’s random it changes everytime I view that page. I need them all to move, does anyone have any suggestions?
Thank you.
onClipEvent (load) {
//data you may want to change
posx =478.9
posy =235.4
width = 5;
height = 5;
//speed = Math.round(Math.random()*2)+1;
speed = Math.random()*.35;
//initial positions
x = this._x=posx+Math.random()*width;
y = this._y=posy+Math.random()*height;
x_new = posx+Math.random()*width;
y_new =posy+ Math.random()*height;
}
onClipEvent (enterFrame) {
//x movement
if (x_new>this._x) {
sign_x = 1;
} else {
sign_x = -1;
}
dx = Math.abs(x_new-this._x);
if ((dx>speed) || (dx<-speed)) {
this._x += sign_x*speed;
} else {
x_new = posx+Math.random()*width;
}
//y movement
if (y_new>this._y) {
sign_y = 1;
} else {
sign_y = -1;
}
dy = Math.abs(y_new-this._y);
if ((dy>speed) || (dy<-speed)) {
this._y += sign_y*speed;
} else {
y_new =posy+Math.random()*height;
}
}