GameMaker 0 Restitution But Still Bouncing

D

djrain

Guest
So I have a wall object that is set to kinematic with 0 density and 0 restitution. I also have a dynamic ball object set to 1 restitution and 1 density.

I would expect that when these objects collide, the ball would not bounce off the wall at all (since the restitution values are multiplied together to get the resulting bounce factor, unless I'm mistaken). But my ball seems to bounce off the wall with full speed. What's the deal?
 

Jezla

Member
A value of one is actually high for restitution (see the manual). In any case, if you remember Newton's laws, the ball will still bounce slightly even if the restitution is zero.
 
D

djrain

Guest
A value of one is actually high for restitution (see the manual). In any case, if you remember Newton's laws, the ball will still bounce slightly even if the restitution is zero.
Yes, a value of one means a perfectly elastic collision.

But like I said, I was under the impression that the two restitution values would be multiplied together to get the resulting bounce. This is how it worked in my previous game engine (which also used Box2D), and that seemed intuitive to me. That way, a value of 0 effectively cancels any bounciness from the other object, and a value of 1 will have no effect. This method worked out perfectly for what I want to do.

The GMS documentation doesn't specify, but I guess Box2D is simply taking the larger of the two restitution values and using that. But this doesn't work out for my scenario, in which I want balls to bounce off each other at full speed, but only bounce off walls at about 0.25. To get the balls to bounce off each other at full speed, I'd have to set their restitution to 1. But then they will bounce off of walls at full speed regardless of the restitution of the wall, which is unintuitive and inconvenient. How am I supposed to make this work?
 

Jezla

Member
According to the Box2D docs, the behavior you're seeing is how its supposed to work. If two fixtures have differing restitutions, the result is weighted toward the higher value, they're not multiplied. To manually cancel the bounce of the ball, you'd have to calculate the vector and apply a countering force or impulse.
 
D

djrain

Guest
According to the Box2D docs, the behavior you're seeing is how its supposed to work. If two fixtures have differing restitutions, the result is weighted toward the higher value, they're not multiplied. To manually cancel the bounce of the ball, you'd have to calculate the vector and apply a countering force or impulse.
Yeah, the result is exactly the higher value (not just weighted towards it).

This system is highly unintuitive. If you throw a basketball (highly bouncy) at a pillow (not bouncy), the basketball shouldn't bounce off at full speed! Duh! So I don't know why Box2D set this as the default.

GameMaker should add an option to use other restitution functions, like the product of the two values as I suggested here. I believe this would only require overriding the Box2D restitution mixture function, so it shouldn't be difficult. I'm not sure if it would be a game preference or a function to use in real time, but either way, this would be extremely useful. We shouldn't have to manually apply extra forces to get the right results when there's such a simple solution.
 
Last edited by a moderator:

Jezla

Member
This system is highly unintuitive. If you throw a basketball (highly bouncy) at a pillow (not bouncy), the basketball shouldn't bounce off at full speed! Duh! So I don't know why Box2D set this as the default.
Because Box2D simulates rigid bodies, not soft bodies (like a pillow), unless you use the physics particles. It looks like Box2D does have a way to override the restitution, but apparently GM doesn't incorporate it (unless I'm reading it wrong).
 
H

HammerOn

Guest
A physics simulation is a perfect world. Perfect rounded circles, perfect smooth edges, perfect solid shapes, unlike the real world.
This means that no matter the settings you use, a ball will never stop on a slope because it has a perfect circumference and their surfaces are infinitely smooth.
A basketball doesn't bounce off a pillow because its kinetic energy is transferred to the pillow making it deform. It bounces off a wall because it deforms and keep its kinetic energy. In the simulation, however, there is little to no energy transfer because the shapes are infinitely hard and the ground is static.

Physics engines give you a realistic physical behavior, not a realistic object simulation. You have to think about and come with ways to simulate them by yourself.
The hardest way is simulating its material and shape imperfection, the easiest way is simulation it's behavior applying forces, the improper way and what people usually do, is manually setting variables like velocity. With the last, you break the only thing the physics engine is good with, a realistic physical behavior. If it doesn't stop rolling down a slope, just apply a negative torque equal to its angular force or make it a polygon. If you want it to not bounce, just make it stop applying a negative force equal to its velocity.
 
Last edited by a moderator:
D

djrain

Guest
Because Box2D simulates rigid bodies, not soft bodies (like a pillow), unless you use the physics particles. It looks like Box2D does have a way to override the restitution, but apparently GM doesn't incorporate it (unless I'm reading it wrong).
In any event, the fact is that they should incorporate it. I never had any problems with restitution using the product of values method -- everything pretty much worked out just by setting the right values. But now I have to do extra work to accomplish the same thing. Not to mention extra work for the processor.

If it wouldn't be too difficult to add that as a preference, then that's a no-brainer.
 
Top