Legacy GMPhysics Box2D Bouncing off Walls

E

eDevGames

Guest
I have been having issues with the default physics 2d engine. I have two 2d games, a minigolf, and a pool game, both of which use the built-in physics engine in a top-down format. The issue is that when the balls bounce off walls, their collision isn't in the same direction. So basically if the ball bounces off the walls four times, it can go from a direction of 35 degrees to being perpendicular to the walls. I have tried changing the different values various times, but have had no luck yet.

The physics properties of the golf ball:
Density: .5
Restitution: .8 (I have tried 0 and 1 for this already)
Collision Group: 1
Linear Damping: .6 (I have tried 0 for this already)
Angular Damping: .1 (I have tried 0 for this already)
Friction: 1

Golf Wall:
Density: 0
Restitution: 0 (I have tried 0 and .8)
Linear Damping: .4
Angular Damping: .0

For the variables above, there are been other options I have tried in the past that I cannot remember the exact values.

icuurd12b42

TMC Founder
GMC Elder
I'm quite sure the problem is the ball spinning

set density and restitution to 1 (everything same mass)
set the linear dampening to 0 (go on for ever)
set the restitution to 1 (bounce forever)
set the friction to 0 (touching things has no effect)
set angular damping to 0, spin like crasy!

running that when a ball hit a wall the walls should fly out the opposite direction... not what you want...

with friction of 0 the ball should not spin aside the way you initially apply velocity... applying velicity may induce spin depending on the function you use. to prevent this try setting the velocityx/y variables directly.

a small amount of friction with balls should allow incurring spin with other balls... and if the wall has some friction then the balls would bounce off taking spin into account.

set the wall linear dampening to *100000 (no moving)
set the wall mass to *100000 (basically unmovable compared to the ball mass of 1)
set the wall angular dampening to *100000 (cant incur spin

the wall should stay still

set the ball angular dampening to *10000 to stop it from spinning...

*Or whatever the largest possible value is

FYI you can find the specs for cue ball and regular ball sizes, friction, mass and restitution online, as well as the bumper rails... I found it all when I did my pool table tutorial 10 years ago... you can plug in the actual numbers in there and it should all work...

E

eDevGames

Guest
Sorry, I should have specified that the walls do not move, since they have a density of 0. Thanks for the other values, I will try them out when I get home. Also, for the whole spinning issue, I set phy_fixed_rotation to true, which based on the docs it says that it should prevent spinning. Is this the kind of spinning you were referencing when you said it caused the issue?

icuurd12b42

TMC Founder
GMC Elder
0 works now? good to know

Matt Hawkins

Member
If your walls are made of several objects, say a vertical wall is made of x amount of blocks, this can cause weird collisions when an object hits the seams of the blocks.
Also it might help to increase the physics iterations and update speed to increase precision with -
Code:
``````physics_world_update_speed(room_speed * 2);
physics_world_update_iterations(30);``````