If you don't want to read the whole novel, the summary and images are at the bottom.
I would image this being made with a KinematicBody2D
This node has a function called is_on_floor()
which returns true/false if the node is on the floor or not.
It also has another one which is called is_on_wall()
which also returns a true/false value. The problem with this second one is, that we also need on which side the collision happened.
You can move the node with move_and_slide()
and after it, you can get the collision data with get_slide_collision()
. This function returns a KinematicCollision2D
that has a property called normal
which contains the collision's direction. This is a Vector2
type varialbe, so you need it's x
value to determine on which side the collision happened.
TL;DR
Node setup

Code on node

I wrote this in a hurry and didn't check if it's working. If it doesn't, let me know.