Prevent a physic body to make very small bounces

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By tkon3

Hi,

I use a ball as a physicbody2d.
When I set bounce to 0, the ball doesn’t bounce which is expected.
When I set bounce to > 0, the ball is bouncing which is also expected.

However, after few vertical bounces, the ball keeps doing very small bounces which are not visible.
If I print colliding bodies :

print(get_colliding_bodies())

I get something like :

[StaticBody2D:[StaticBody2D:1347]]
[]
[]
[StaticBody2D:[StaticBody2D:1347]]
[StaticBody2D:[StaticBody2D:1347]]
[StaticBody2D:[StaticBody2D:1347]]
[StaticBody2D:[StaticBody2D:1347]]
[StaticBody2D:[StaticBody2D:1347]]
[]
[StaticBody2D:[StaticBody2D:1347]]

In this case, the ball doesnt move but switches between a colliding state and a non colliding state.

How can I prevent this since I want to track when the ball has a collision (is on a floor/wall) ?
Note that if I change to bounce=0 during the process, this behavior stops.

Thank you

Did you try move_and_slide_with_snap() for the ball (assuming it is KinematicBody2D)

litelo | 2022-02-06 07:24