D
djrain
Guest
By default, Box2D calculates the restitution of a collision by simply taking the higher of the restitution values of the two bodies colliding. I have no idea why it does it this way, because it seems totally unintuitive and not very useful.
This method does not work well in many situations. For instance, say you have a bouncy ball, a concrete surface, and a sandy surface in your game. Intuitively, bouncy balls are very bouncy, concrete is quite bouncy, but sand is not at all. So you set the ball's bounciness to 0.9, the concrete to 0.6, and the sand to 0. But this won't work using the default method, because both collisions will just use the higher value, which is the ball at 0.9. That's no good!
The only thing you could do, then, is set the ball's bounciness to zero, the concrete to 0.9 and the sand to zero. Then you would get the collisions you want with the bouncy ball, but this also sucks because you might have other objects in the game that should NOT bounce off the concrete. So basically, there's no way to get the right behavior in this case.
This default method is what GameMaker uses. However, Box2D gives the option to set the restitution function to anything you want! A much more versatile and intuitive option is to take the product of the two values. Other physics engines use this method by default. This is great because you can simply set the intuitive values I stated in the first place, and everything works. When the ball hits the concrete, it will collide with 0.9 x 0.6 = 0.54 bounciness. This makes sense because the ball is super bouncy, but the concrete dampens it a bit. And when the ball hits the sand, it will not bounce at all because 0.9 x 0 = 0. Perfect!
I suggest that GameMaker add an option to change this restitution function. I'd be pretty happy with just the added multiplication method, but a fully customizable function would be even better. This would make physics a whole lot easier to work with.
If you agree, please like and leave a comment and hopefully the devs will take notice.
(And if anyone knows of a way to accomplish this, perhaps by editing some file, please let me know. It would be very useful for my current project.)
This method does not work well in many situations. For instance, say you have a bouncy ball, a concrete surface, and a sandy surface in your game. Intuitively, bouncy balls are very bouncy, concrete is quite bouncy, but sand is not at all. So you set the ball's bounciness to 0.9, the concrete to 0.6, and the sand to 0. But this won't work using the default method, because both collisions will just use the higher value, which is the ball at 0.9. That's no good!
The only thing you could do, then, is set the ball's bounciness to zero, the concrete to 0.9 and the sand to zero. Then you would get the collisions you want with the bouncy ball, but this also sucks because you might have other objects in the game that should NOT bounce off the concrete. So basically, there's no way to get the right behavior in this case.
This default method is what GameMaker uses. However, Box2D gives the option to set the restitution function to anything you want! A much more versatile and intuitive option is to take the product of the two values. Other physics engines use this method by default. This is great because you can simply set the intuitive values I stated in the first place, and everything works. When the ball hits the concrete, it will collide with 0.9 x 0.6 = 0.54 bounciness. This makes sense because the ball is super bouncy, but the concrete dampens it a bit. And when the ball hits the sand, it will not bounce at all because 0.9 x 0 = 0. Perfect!
I suggest that GameMaker add an option to change this restitution function. I'd be pretty happy with just the added multiplication method, but a fully customizable function would be even better. This would make physics a whole lot easier to work with.
If you agree, please like and leave a comment and hopefully the devs will take notice.
(And if anyone knows of a way to accomplish this, perhaps by editing some file, please let me know. It would be very useful for my current project.)