# Bouncing Ball, Math problem

**URL:** <https://forum.kirupa.com/t/bouncing-ball-math-problem/178373>\
**Category:** flash\
**Created:** [February 9, 2006, 10:59pm UTC](https://forum.kirupa.com/t/bouncing-ball-math-problem/178373 "2006-02-09T22:59:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![coop](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@coop](https://forum.kirupa.com/u/coop)\
**Post date:** [February 9, 2006, 10:59pm UTC](https://forum.kirupa.com/t/bouncing-ball-math-problem/178373/1 "2006-02-09T22:59:40Z")

</div>

Hi all,

I have a math problem I think.  
I want a ball to bounce forward and then backward in an ark.

I have it bouncing forward in the ark and stopping where I want it to, but then I carn’t get it to bounce back in the same way.

[AS]  
var xspeed = 7;  
var yspeed = 10;  
ball\_mc.\_x = 10;  
ball\_mc.\_y = 300;  
drag = .98;  
gravity = .2;  
bottom = 300;  
one\_btn.onRelease = function() {  
ball\_mc.onEnterFrame = function() {  
trace(this.\_x)  
this.\_x += xspeed;  
this.\_y -= yspeed;  
gravity -= .05;  
yspeed = yspeed_drag+gravity;  
xspeed = xspeed_drag;  
if (this.\_y\>=bottom) {  
yspeed = -yspeed;  
xspeed = -xspeed;  
}  
};  
};

[/AS]
