• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

 [Suggestion] Change Collision Restitution Function

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.)
 
D

djrain

Guest
in the collision event you can get the phy_col_normal_x and phy_col_normal_y of all the phy_collision_points... average them out... the incidence vector being the Normalised Vector of phy_speed_x, phy_speed_y....

you can calculate the bounce yourself.. you would need to set the restitutions factors to 0 and use your own restitution variables
Thanks for the suggestion. Sounds like more work than it's worth at the moment, but I may have to try that at some point.

Seems like it would be fairly straightforward to just add an option in GameMaker to change the function. @rmanthorp @rwkay What do you think?
 

GMWolf

aka fel666
in the collision event you can get the phy_col_normal_x and phy_col_normal_y of all the phy_collision_points... average them out... the incidence vector being the Normalised Vector of phy_speed_x, phy_speed_y....

you can calculate the bounce yourself.. you would need to set the restitutions factors to 0 and use your own restitution variables
Alternatively, you can just create your own physics engine...

Seriously? Is that what the coding experience should be like in GML?
 
M

Misty

Guest
in the collision event you can get the phy_col_normal_x and phy_col_normal_y of all the phy_collision_points... average them out... the incidence vector being the Normalised Vector of phy_speed_x, phy_speed_y....

you can calculate the bounce yourself.. you would need to set the restitutions factors to 0 and use your own restitution variables
Why even use a physics engine at all then? Your advice is telling him to disable the physics response and reprogram them himself.
 
Top