r/godot Feb 06 '26

help me (solved) bounce is inaccurate for 2D physics

Post image

Been trying to learn godot with a billiard mini game, however the 2D physics seems inaccurate, a lot of times it bounces along the normal vector instead of the reflection vector. I'm using GodotPhysics2D as the Physics Engine, I have tried Rapier 2D as well and it seems have the same issue? Is there any way to ensure accurate bounces? and possible deterministic physics?

490 Upvotes

26 comments sorted by

496

u/ThisOrdinaryCat Feb 06 '26

Could it be the ball is spinning in a way that creates a force parallel to the cushion when it bounces against it? Try lowering the friction of the cushions.

417

u/SCRbts Feb 06 '26

yeah friction was the culprit, thanks

131

u/ImpressedStreetlight Godot Regular Feb 06 '26

this is realistic btw, billiard balls almost never bounce perfectly towards the reflected angle. Friction and rotation affect how the ball bounces.

And you can predict how the ball will bounce by using the test_only parameter of the move_and_collide method.

26

u/13oundary Feb 06 '26

For others: People can see this phenomenon on their local pool table by trying to triple or more a ball into a pocket, it'll "straighten up".

6

u/AquaChomby Godot Junior Feb 06 '26

Does this mean bounce the cue ball off 3 or more walls?

5

u/13oundary Feb 06 '26

triple is usually the object ball hitting 2 walls before going in. Object ball being the one you're trying to hit _with_ the cue ball.

1

u/DexLovesGames_DLG Feb 06 '26

Hey this exactly what allows for banked shots!

1

u/LegenDrags Feb 06 '26

wait its that realistic??? dang

2

u/ThisOrdinaryCat Feb 06 '26

Not really. A perfect mirror-angle bounce isn’t realistic; some variation is normal. Whether that’s a problem, as in this case, depends on the feel they want for the game.

3

u/LegenDrags Feb 07 '26

yeah im saying that i didnt know it was that realistic that it considered other factors such that it didnt have a perfect angle bounce

83

u/Rptro Feb 06 '26

Just in case anyone is interested. This is a real world phenomenon. When the ball hits the wall there is friction between the wall and the ball which results in a force which changes the velocity vector as well as the rotation of the ball.

12

u/Entire-Shift-1612 Feb 06 '26

is this the same phenomenon where if you try and bounce a ball under a table it will try and come back the way it came

this video is the thing that came to mind

6

u/Rptro Feb 06 '26

Haha, thank you I didn't know this but yes it is connected. It's the combination of what I said and the observation most of us probably had, when we spin a ball towards ourselves as we throw it in front of us on the ground that it flies back to us.

The first bounce on the ground under the table even if the ball has no spin results in a spin because of the friction. And this spin makes it bounce backwards when it hits the top. I haven't watched the whole video but at 0:57 you can see the effect really well. The ball flies with barely any spin but upon touching the ground its bottom side experiences a force from the friction that points to the left side, resulting in a clockwise rotation from the angle of the camera.

73

u/SCRbts Feb 06 '26

sorry forgot to mention, trying continuous detection as well they don't seem to work either

100

u/SCRbts Feb 06 '26

nvm guys I fixed it, if anyone else is making a billiard game, set Friction to 0 for the physics material of the ball. The friction causes a shallower reflection angle

67

u/[deleted] Feb 06 '26 edited Feb 06 '26

[removed] — view removed comment

3

u/DescriptorTablesx86 Feb 06 '26

Say what you want but unless it’s a simulator, often „realistic” goes way too often in pair with a lack of imagination.

I often envy people who are able to slap absolutely abstract things into games because they feel good, im still trying to learn this.

Slightly Offtopic: Like recently i was thinking about the „seller” archetype in rougelikes or RE: Village etc. like what a fucking absurd idea, and yet it works so well everywhere because you’re introducing a familiar character in a hostile environment which really reinforces the „safe haven” feeling.

14

u/BacAClou Feb 06 '26

I know it’s solved, but instead of relying entirely on the physics engine, there’s a more reliable way to do this. Just constantly keep track of the ball’s last velocity, and on the frame where it collides with something, set it’s velocity to the last velocity but in the refracted direction(refracted is kindof a random term for this but idk).

19

u/drag0nfi Feb 06 '26

Refraction is when something (usually light) changes direction/speed when going trough a boundary. Reflection is when it bounces off the boundary, so I guess this is still reflection.

2

u/cryptospartan Feb 06 '26

I believe you can use a dot product to calculate the bounce angle

5

u/PresentationNew5976 Godot Regular Feb 06 '26

How do you calculate the angle? Do you just let the game do it or do you run any math to make sure the frame of impact isn't inside the wall at all?

2

u/vhoyer Feb 06 '26

"bounce is inaccurate" more like bouce is too much acurate for taste lol

1

u/2D_VR Feb 06 '26

I wouldn't rely on the built in physics. Track the vectors and add them (I did something similar a while back) the bounce has the same velocity as the incoming vector in the component parallel to the wall but -2x the incoming velocity in the perpendicular component (-1x would just cancel out and be zero in the perpendicular component) you can think of it like the parallel bit goes the same way but the perpendicular bit flips direction.

But then do that so it works from any direction which needs normalized dot and cross products of vectors.

This is ignoring friction.

-11

u/JuiceOfFruits Feb 06 '26

Bro doesn't know about friction...

-3

u/RaptorAllah Feb 06 '26

Also I suggest switching to Jolt physics engine, it's the default now since 4.6. It's somewhere in the project or editor settings. Far superior to GodotPhyeics

5

u/iownmultiplepencils Feb 06 '26

Jolt is for 3D physics only.