Hi ! I have some bouncing balls that I am using as navigational link buttons. However at the moment some of the balls can be in front of another ball or balls. I would like to be able to make it that if the balls collide that they bounce off each other. On each ball there is three frames of actionscript as shown below, would it be difficult to add some script to make them collide. Any help would be appreciated. Thanks
********Frame 1********
//Set the bounds
bounds = new Object();
bounds.left = 50;
bounds.right = 730;
bounds.top = 100;
bounds.bottom = 488;
//Set initial speed vector
speed = new Object();
speed.x = 10;
speed.y = 10;
//Set friction to act on ball
friction = .98;
//Set boolean for drag property
drag = false;
//Gravity and Friction toggle variables
friction_t = true;
gravity_t = true;
********** Frame 2 ***********
if(drag) {
//If the ball is being dragged, recalculate it's speed
if(old_x <> this._x || old_y <> this._y) {
speed.x = (this._x - old_x) / 4;
speed.y = (this._y - old_y) / 4;
}
old_x = this._x;
old_y = this._y;
} else {
//move ball
this._x += speed.x;
this._y += speed.y;
//Check bounds
if(this._x < bounds.left) {
speed.x *= -1;
this._x = bounds.left;
} else if(this._x > bounds.right) {
speed.x *= -1;
this._x = bounds.right;
} else if(this._y < bounds.top) {
speed.y *= -1;
this._y = bounds.top;
} else if(this._y > bounds.bottom) {
speed.y *= -1;
this._y = bounds.bottom;
}
if(friction_t) {
//apply friction to horizontal plain
speed.x *= friction;
//apply y friction if gravity is off
if(!gravity_t){
speed.y *= friction;
}
}
if(gravity_t) {
//apply gravity to vertical plain
if(speed.y > 0){
speed.y *= 1.3;
} else if(speed.y < 0){
speed.y *= .68;
}
if((speed.y < 2) && (speed.y > -2) && (this._y < (bounds.bottom - 2))) {
speed.y = 2;
}
if((speed.y == 2) && (this._y > (bounds.bottom - 3))) {
speed.y = 0;
this._y = bounds.bottom;
}
}
}
***********Frame 3***********
gotoAndPlay(this._currentframe-1);
********Frame 1********
//Set the bounds
bounds = new Object();
bounds.left = 50;
bounds.right = 730;
bounds.top = 100;
bounds.bottom = 488;
//Set initial speed vector
speed = new Object();
speed.x = 10;
speed.y = 10;
//Set friction to act on ball
friction = .98;
//Set boolean for drag property
drag = false;
//Gravity and Friction toggle variables
friction_t = true;
gravity_t = true;
********** Frame 2 ***********
if(drag) {
//If the ball is being dragged, recalculate it's speed
if(old_x <> this._x || old_y <> this._y) {
speed.x = (this._x - old_x) / 4;
speed.y = (this._y - old_y) / 4;
}
old_x = this._x;
old_y = this._y;
} else {
//move ball
this._x += speed.x;
this._y += speed.y;
//Check bounds
if(this._x < bounds.left) {
speed.x *= -1;
this._x = bounds.left;
} else if(this._x > bounds.right) {
speed.x *= -1;
this._x = bounds.right;
} else if(this._y < bounds.top) {
speed.y *= -1;
this._y = bounds.top;
} else if(this._y > bounds.bottom) {
speed.y *= -1;
this._y = bounds.bottom;
}
if(friction_t) {
//apply friction to horizontal plain
speed.x *= friction;
//apply y friction if gravity is off
if(!gravity_t){
speed.y *= friction;
}
}
if(gravity_t) {
//apply gravity to vertical plain
if(speed.y > 0){
speed.y *= 1.3;
} else if(speed.y < 0){
speed.y *= .68;
}
if((speed.y < 2) && (speed.y > -2) && (this._y < (bounds.bottom - 2))) {
speed.y = 2;
}
if((speed.y == 2) && (this._y > (bounds.bottom - 3))) {
speed.y = 0;
this._y = bounds.bottom;
}
}
}
***********Frame 3***********
gotoAndPlay(this._currentframe-1);