# Adding collision to this gravity code

**URL:** https://forum.kirupa.com/t/adding-collision-to-this-gravity-code/197412
**Category:** flash
**Created:** [August 16, 2006, 4:33am UTC](https://forum.kirupa.com/t/adding-collision-to-this-gravity-code/197412 "2006-08-16T04:33:32Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)
#### Post date: [August 16, 2006, 4:33am UTC](https://forum.kirupa.com/t/adding-collision-to-this-gravity-code/197412/1 "2006-08-16T04:33:32Z")

</div>

I have a move that has a bunch of boxes that drop into the screen and bounce with a little gravity at the bottom of the window.

```auto
for (i=0; i<4; i++) {
 var clip:MovieClip = attachMovie("circle", "circle"+i, getNextHighestDepth());
 clip._x =i*randRange(0, 600)
 clip._y = i*randRange(-200,-600)
 clip.xspeed = 30;
 clip.yspeed = 30;
 clip.bottomedge = 600;
 clip.leftedge = 0;
 clip.rightedge = 1000;
 clip.gravity = 6;
 clip.drag = .95;
 clip.bounce = .8;
 clip.onEnterFrame = function() {
  with (this) {
   _x += xspeed;
   _y += yspeed;
   if (_x+_width/2>rightedge) {
    _x = rightedge-_width/2;
    xspeed = -xspeed*bounce;
   }
   if (_x-_width/2<leftedge) {
    _x = leftedge+_width/2;
    xspeed = -xspeed*bounce;
   }
   if (_y+_height/2>bottomedge) {
    _y = bottomedge-_height/2;
    yspeed = -yspeed*bounce;
   }
   xspeed = xspeed*drag;
   yspeed = yspeed*drag+gravity;
  }
 };
}

```

I’m having some issues getting the collision built in and am not really looking forward to starting from scratch, anybody have any ingenious ideas?  
[whisper]Canadian?:Dhisper]
