How to avoid having RigidBody2D bounce on a flat surface

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

Hi there,

I’m making a game with RigidBody2D as my main character.
The reason I’m using a RigidBody2D and not a KinematicBody2D is that I don’t want to re-code the physics, especially when character is in the air and could be subject to multiple outside factors (breaking, wind, boost etc).

I’m trying to make a game with some very similar mechanics than:

The problem I have is that when applying a force to my body, it randomly jumps as if it were colliding with the ground.

The issue is that this happens even on a perfectly flat surface like when drawing a Collision2D with a programmatically generated rectangle.

I’ve tried messing with the gravity, friction, safe margins with one way directions etc, but didn’t manage to avoid those weird bumps. (BTW I’m not really sure I properly explore the one way direction, as I didn’t really manage to see any changes when moving the safe margins).

I’ve also looked at all the similar issues I found via Google:

(and a lot others more or less closely related to the same issue).

All the answers I saw revolved around either using a KinematicBody2D or switching somehow dynamically to a Kinematic mode on the RigidBody2D.

  1. I understand using a KinematicBody2D for everything gravity related would mean I need to recode everything gravity wise. How complex would that be for a game such as the ones mentioned above?

  2. To your knowledge, is using a KinematicBody2D the only way to avoid weird bumps like the ones I described?

  3. I understand that the issue is related to some kind of physics approximation, would there be a way for me to to use _integrated_forces to skip some collisions or adjust the applied force direction I have a way to detect the angle was badly approximated?

  4. When switching the RigidBody2D to a Kinematic mode, you need to recode the move_and_slide your self. Is there a better way?

What I’m trying to achieve in the end is something like “move_and_slide_with_snap” for a RigidBody2D, and avoiding those weird bumps.

Thanks a ton for your help,

I’ve also looked at some Unity videos where this problem doesn’t seem to occur, I was really hoping to solve the problem in Godot 3.2.

:bust_in_silhouette: Reply From: larrxi

Use capsuleshape and not rectangleshape. In the motorbike game it is two circle shapes I guess.

Or try a Collisionpolygon2D and make the the front bend up a bit.

Thanks a lot for your answer.

I’m actually using 2 circles as the wheels for now, but have been experimenting with all kind of shapes.

I think it boils down to the physics engine doing some approximations ending up creating collisions on flat surfaces.

Just creating a flat surface, putting a circle on it and adding forces reveal the problem.

Here is an example illustrating the problem: https://youtu.be/V4qIOgFBjKY?t=920

nostalgic_gamer | 2020-11-09 08:40