# Random Cirlces Help

**URL:** https://forum.kirupa.com/t/random-cirlces-help/21182
**Category:** flash
**Created:** [May 18, 2003, 4:32pm UTC](https://forum.kirupa.com/t/random-cirlces-help/21182 "2003-05-18T16:32:18Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Comglomo](https://avatars.discourse-cdn.com/v4/letter/c/e19adc/32.png) [@Comglomo](https://forum.kirupa.com/u/Comglomo)
#### Post date: [May 18, 2003, 4:32pm UTC](https://forum.kirupa.com/t/random-cirlces-help/21182/1 "2003-05-18T16:32:18Z")

</div>

Hi, I downloaded the random circles on this site. Its a good code, but it seems that the circles that move, just go everywhere. How would I make it so that when the circles hit a lone or something, stop and go in another direction.

You can find the code in the kirupalab. I think…

---

<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: [May 18, 2003, 5:31pm UTC](https://forum.kirupa.com/t/random-cirlces-help/21182/2 "2003-05-18T17:31:53Z")

</div>

do you mean when they collide, they go the opposite direction. I think its called flash dectection. 🙂 im not sure how to do it though, mabye Kax will know. 🙂

---

<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: [May 18, 2003, 6:20pm UTC](https://forum.kirupa.com/t/random-cirlces-help/21182/3 "2003-05-18T18:20:24Z")

</div>

welcome to the forums, Comglomo, are you talking about these circles [http://www.kirupa.com/lab/circles.htm](http://www.kirupa.com/lab/circles.htm) ?

you’d have to use the hitTest function for collision between circles and that would probably be complicated if you had more than 2 circles…

If you are trying to do a realistic bounce on the borders, all you have to do is check the coordinates of the circles and switch them when they become greater or less than the boundaries…

let me clarify; if the circle is heading right, then you will tell the circle to inverse his \_x speed in order to go the other way

here the variables xdirection and ydirection are the x and y speed of the circles

```auto

onClipEvent (enterFrame) {
	if (this._x>=_root.rightwall._x || this._x<=_root.leftwall._x) {
		_root.xdirection *= -1; 
	}
if (this._y>=_root.bottomwall._y || this._y<=_root.topwall._y) {
		_root.ydirection *= -1; 
}
}

```

---

<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: [May 18, 2003, 6:59pm UTC](https://forum.kirupa.com/t/random-cirlces-help/21182/4 "2003-05-18T18:59:09Z")

</div>

Yes, thats what I was looking for, But should I make the right wall, left wall, bottom wall, and top wall movie clips?  
Thanks for your help.

---

<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: [May 18, 2003, 7:08pm UTC](https://forum.kirupa.com/t/random-cirlces-help/21182/5 "2003-05-18T19:08:07Z")

</div>

i did a little example:

\<embed src=http://membres.lycos.fr/mlkdesign/kirupa/circles.swf height=300 width=300 type=application/x-shockwave-flash\>

and here’s the fla:  
[http://membres.lycos.fr/mlkdesign/kirupa/circles.fla](http://membres.lycos.fr/mlkdesign/kirupa/circles.fla)

mmhh, i dunno why the bottom bar doesnt show though :-\  
reload the page and you’ll have a different speed…

---

<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: [May 18, 2003, 7:52pm UTC](https://forum.kirupa.com/t/random-cirlces-help/21182/6 "2003-05-18T19:52:54Z")

</div>

Ok, you’ve got the idea of what I wanted, but if you watch for a little bit, all it does is bounce of the sides of the walls, I wanted it to have random movement, and if when one of the circles touches the wall, it will stop and turn around and go another way.  
Your example never like stops anywhere, it just like keeps going… and stuff.  
Thanks for your help.
