(ANSWERED) how to prevent player from getting inside a wall?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By PugMasterPug
:warning: Old Version Published before Godot 3 was released.

what I mean is that I have created a player, and it goes towards a wall, it gets a few pixels inside the wall, even if the player stops moving, it stays a fex pixels inside the wall.

This affects me because it also happens with the floor, so sometimes when I jump, the player gets a bit inside the floor, so then when I try moving, the player gets stuck.

I am using the default collision of the CollisionShape2D, the maxDepth is set to 0, the gravity works with the default RigidBody2D gravity, the player moves horizontally with set_linear_velocity () and I have no idea how I could fix this

:bust_in_silhouette: Reply From: mateusak

This took me a while to figure out when I began. You see, a lot of problems will come up if you don’t set up your colliders properly, not only getting a little under the floor.

The most important thing you have to know is this:
Every side of a collider that is intended to interact with another collider should have another collider pointing in that direction using a RayShape2D. The function of this shape is not to collide, but to push away.

Example:
The bottom side of your player collider is intended to interact with the ground collider, therefore you setup another collider using a RayShape2D pointing downwards. This will prevent any problems, such as getting stuck, getting under the ground, etc.