Hi coding friends, I am a beginning coding learner on coding train. I am trying to simulate the gravity. But I find it confusing when I am trying to set when it is gonna bounces back. now it just keeps bouncing back at the same height like playing basketball.
float y = 0;
float speed=2;
float g=2;
void setup(){
size(640,360);
}
void draw(){
background(0);
noStroke();
fill(255);
circle(width/2,y,50);
y=y+speed;
speed=speed+g;
if (y>=height){
speed=speed*-1+g;
}
println(speed,y);
}