CharacterBody2D collision with one or more CharacterBody2D

Godot Version

4.6.3

Question

Hey there! I’m wondering on how I can check if a CharacterBody2D collided with the top or the bottom of another one(or any physics body in general)
Here’s my code:

func _physics_process(delta: float) → void:
	velocity = direction * speed
	move_and_slide()
	for i in get_slide_collision_count():
		var collision = get_slide_collision(i)
		var collider = collision.get_collider()

		if collider is CharacterBody2D:
			collider.direction.x *= -1
        #Depending on where the Body collided with another, the direction will be changed. But i just have no idea on how to figure that out.

Try using collision.get_normal() to get the colliding body’s normal at the collision point. If the collider is a simple convex shape, then you should be able to tell whether the collider is above or below the current body by the collision normal’s y component.

Thanks!