We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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)
Answers
This must be a FAQ by now.
The fast stuttering is caused by line speed *-1
When ball is still in the bounce zone
Replace by -abs(speed); // always negative
do i need to replace the bounce value by a negative number?
https://forum.processing.org/two/discussion/comment/39257/#Comment_39257
https://forum.processing.org/two/discussion/comment/35630/#Comment_35630
https://forum.processing.org/two/discussion/comment/35630/#Comment_35630
https://forum.processing.org/two/discussion/comment/19996/#Comment_19996
https://forum.processing.org/two/discussion/comment/15554/#Comment_15554
https://forum.processing.org/two/discussion/comment/12804/#Comment_12804
https://forum.processing.org/two/discussion/comment/10295/#Comment_10295
https://forum.processing.org/two/discussion/comment/2085/#Comment_2085