Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the gravity ball is shaking, Is that because of the precision of float? #219

Open
ghost opened this issue Jul 20, 2018 · 2 comments
Open

Comments

@ghost
Copy link

ghost commented Jul 20, 2018

At some conditions, the ball won't finally 'stopped', actually it won't, I mean I can see it still shaking at the bottom of the window. Is that because of the precision of float? I have tried debugged it, only to find that it won't shaking if the speed is around +-0.0x

@ghost
Copy link
Author

ghost commented Jul 20, 2018

float x = 100;
float y = 0;

float speed = 0;
float gravity = 0.1;

void setup(){
size(200, 40);
}

void draw(){
background(255);

fill(0);
rectMode(CENTER);
ellipse(x, y, 10, 20);

y = y + speed;
speed = speed + gravity;

if( y > height ){
speed = speed * -0.3;//energy of motion lose.
//after collision, the reverse speed will slow.

y = height;

}

}

@ghost
Copy link
Author

ghost commented Jul 20, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants