Bouncing balls

Ok ive got this ball that bounces around the screen. There are a bunch more that are made with the duplicate movie clip command. I want them to bounce off eachother, as well as the walls. The problem is, i cant just put the code on the original ball because then balls want to bounce off themselves which creates problems. So my question is, is there some kind of loop I can use to make it so each duplicate ball will bounce off the others but not itself?

What does your current code look like?

Say you have a method isThereCollision that tests the collision between the current clip and a givent clip passed as a parameter, and that you call in an noEnterFrame, you could do

for (allClips in ballContainer) {
    var clip = ballContainer[allClips] ;
    if (clip != this) this.isThereCollision (clip) ;
} ;

You can also check Keith Peters’ excellent billiard class at www.bit-101.com

Note that the for…in loop is not an economic method, because each clip will test the collision with every other clip, so you’ll end up testing the collisions twice. You can use arrays to solve that, but I’m pretty sure that Bit does it in his code :slight_smile:

whoa that bit-101 guy is awesome :slight_smile: amusement for hours, who ever needed games

Yeah this is some pretty neat coding on bit’s site, was stuck there for over an hour :pleased: