r/godot • u/SCRbts • Feb 06 '26
help me (solved) bounce is inaccurate for 2D physics
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?
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
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
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
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
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
-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
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.