Question with bouncing ball

Hello everybody , so recently i wanted to make a realistical bouncing ball , here is the code:

var x = 200; var y = 110; var speed = 0; var bounce = 0.3;

function setup() {

createCanvas(400, 400); }

function draw() {

background(51);

ellipse(x, y, 30, 30);

// the ball starts to drop.

y = y + speed;

// its speed is increasing over time rather than falling at a constant speed

speed = speed + bounce;

// if it hits the ground

if( y >= height){

speed = speed * -1;

speed = speed + bounce;

bounce = bounce + 0.1;

} }

So this works fine, im proud. HOWEVER i have some issues which i cannot understand. The first question is, when i change the bounce value to a slightly larger number ( 0,4 or 0,5) i get a blank page. My second question is, when the ball gets too close to the ground it starts to go up and down really fast and i dont want that. I want the ball to transition smoothly onto the ground. Thanks in advance guys.( p5 js)

Tagged:
Sign In or Register to comment.