2D Physics Engine: bouncing ball w/ inelastic collisions does not come to a stop

风流意气都作罢 提交于 2019-12-05 15:52:37

What I would suggest is to have a block of code that will bounce only if the bounce height is at or above a certain constant that you've defined as the height. You would need some sort of loop structure (or "helper" method as I did below) to calculate the projected bounce height after every bounce of the ball. Then you might be able to do something like this: (assuming that you've entered the "now it's time to bounce method")

private static final int MINIMUM_BOUNCE = 100 //arbitrary value

. . .

if(calculateNewBounceHeight() >= MINIMUM_BOUNCE) {
    bounce();
} else {
    // terminate program?
    // notify user?
    // etc.
}

The only problem with this way is that if you do not terminate at some point, the program will be checking if it can bounce infinitely (if the ball is "rolling" on the baseline). This might cause some memory issues as it is to a certain extent an infinite loop.

Just for clarification: calculateNewBounceHeight() and bounce() are methds that I assume you will be able to create. Does this help at all? Let me know if I missed something or interpreted the question wrong (I might not have read the whole thing).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!