How to detect wall collision and on which side is the wall colliding with?

Godot Version

4.3 stable

Question

How to detect on what side (left or right) a CharacterBody2D is colliding when is colliding with a wall?
For example, if is_on_wall() is true then print on which side is colliding:

extends CharacterBody2D

func _physics_process(delta: float) -> void:
	# ... CODE ...

	if is_on_wall():
		print( On which side is the wall that is colliding with )

	# ... CODE ...
1 Like

you need to get the normal and then normalize it to be -1 for left on x and 1 to positive for right

1 Like