# Bouncing balls

**URL:** <https://forum.kirupa.com/t/bouncing-balls/113210>\
**Category:** Uncategorized\
**Created:** [June 15, 2004, 10:23pm UTC](https://forum.kirupa.com/t/bouncing-balls/113210 "2004-06-15T22:23:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![flashyjack](https://avatars.discourse-cdn.com/v4/letter/f/ecb155/32.png) [@flashyjack](https://forum.kirupa.com/u/flashyjack)\
**Post date:** [June 15, 2004, 10:23pm UTC](https://forum.kirupa.com/t/bouncing-balls/113210/1 "2004-06-15T22:23:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 16, 2004, 7:55am UTC](https://forum.kirupa.com/t/bouncing-balls/113210/2 "2004-06-16T07:55:46Z")

</div>

What does your current code look like?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 16, 2004, 9:05am UTC](https://forum.kirupa.com/t/bouncing-balls/113210/3 "2004-06-16T09:05:26Z")

</div>

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

```auto
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](http://www.bit-101.com)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 16, 2004, 9:11am UTC](https://forum.kirupa.com/t/bouncing-balls/113210/4 "2004-06-16T09:11:31Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 16, 2004, 10:43am UTC](https://forum.kirupa.com/t/bouncing-balls/113210/5 "2004-06-16T10:43:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 16, 2004, 12:02pm UTC](https://forum.kirupa.com/t/bouncing-balls/113210/6 "2004-06-16T12:02:30Z")

</div>

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