# Help with bounce physics and hit test

**URL:** https://forum.kirupa.com/t/help-with-bounce-physics-and-hit-test/217189
**Category:** Uncategorized
**Created:** [February 23, 2007, 11:57pm UTC](https://forum.kirupa.com/t/help-with-bounce-physics-and-hit-test/217189 "2007-02-23T23:57:25Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![East\_High](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@East\_High](https://forum.kirupa.com/u/East_High)
#### Post date: [February 23, 2007, 11:57pm UTC](https://forum.kirupa.com/t/help-with-bounce-physics-and-hit-test/217189/1 "2007-02-23T23:57:25Z")

</div>

This code does what I want except for all the vibrating once the mc has stopped bouncing. I guess it’s still bouncing. :ponder: I threw in a ‘delete.onEnterFrame’ if \_y==floor, but that doesn’t give me the desired results. I want it to bounce for a bit then come to a rest with no vibration.

Can anyone help with this? I’d upload a basic .fla, but I’m restricted from uploads at work. All you need to do is create a 100x300 .fla, make a mc with the instance name of box\_mc, place it at 10y, 25x and paste the code into the actions panel.

```
ActionScript Code:
[FONT=Courier New][LEFT][COLOR=#0000FF]floor[/COLOR] = [COLOR=#000080]250[/COLOR];

```

bounce = [COLOR=#000080]0[/COLOR].[COLOR=#000080]2[/COLOR];  
[COLOR=#0000FF]MovieClip[/COLOR].[COLOR=#0000FF]prototype[/COLOR].[COLOR=#000080]moveWithGravity[/COLOR] = [COLOR=#000000] **function** [/COLOR][COLOR=#000000]([/COLOR]vel:[COLOR=#0000FF]Number[/COLOR], gravity:[COLOR=#0000FF]Number[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]this[/COLOR].[COLOR=#000080]dy[/COLOR] = vel+gravity;  
[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]onEnterFrame[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]\_y[/COLOR] += [COLOR=#0000FF]this[/COLOR].[COLOR=#000080]dy[/COLOR];  
[COLOR=#0000FF]this[/COLOR].[COLOR=#000080]dy[/COLOR] += gravity;  
[COLOR=#0000FF]if[/COLOR] COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]\_y[/COLOR] = [COLOR=#0000FF]floor[/COLOR];  
[COLOR=#0000FF]this[/COLOR].[COLOR=#000080]dy[/COLOR] _= -bounce;  
[COLOR=#000000]}[/COLOR]  
[COLOR=#808080]_/_if (this.\_y == floor) {  
delete this.onEnterFrame;  
}_/\*[/COLOR]  
[COLOR=#000000]}[/COLOR];  
[COLOR=#000000]}[/COLOR];  
box\_mc.[COLOR=#0000FF]onPress[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]this[/COLOR].[COLOR=#000080]moveWithGravity[/COLOR][COLOR=#000000]([/COLOR]-[COLOR=#000080]5[/COLOR], [COLOR=#000080]1[/COLOR][COLOR=#000000])[/COLOR];  
[COLOR=#000000]}[/COLOR];  
[/LEFT]  
[/FONT]
