hey guys, need some more help with a formula. So i have this formula that calculates gravity, which Should be a constant force, and in the program it looks like it is, but for some reason it only happens if i have a collision with the upper wall (if x <= 0) heres the update code for the bounding box and the gravity formula.\
Code:
if (r.getXpos() >= 244)
{
r.setXspeed(r.getXspeed() * -1);
r.setXpos(243);
}
if (r.getXpos() <= 0)
{
r.setXspeed(r.getXspeed() * -1);
r.setXpos(1);
}
if (r.getYpos() >= 452)
{
r.setYpos(451);
r.setYspeed(r.getYspeed() * -1);
}
if (r.getYpos() <= 0)
{
r.setYpos(1);
r.setYspeed(r.getYspeed() * -1);
}
Btw r is a "red ball" its a foreach loop. this part of the code finds collison with the edges fo the screen
Code:
if (r.getGrav() <= 6)
{
r.setGrav(r.getGrav() + 1);
}
r.setYpos(r.getYpos() + r.getYspeed());
r.setXpos(r.getXpos() + r.getXspeed() + r.getGrav());
the if statement is how we calculate gravity until the ball reaches terminal velocity (its max fall speed0
The second part is where we update the balls position based on its speed and gravity.