I want two CharacterBody2D to collide but not block each other juste offering resistance to each other

Godot Version

4.2.2

Question

Hello,

Context

I’m developing a little game inspired by Vampire Survivor to train myself on Godot engine and encounter a problem I cannot solve.

I want my player to be able to push ennemie if it “force” his way in the enemy direction but meet difficulty to move it (feeling like enemies have an actual weight).
Did you have a trick to do something like that?

Game context :

  • Player is a CharacterBody2D with basic movement
func _physics_process(delta) :
	if ennemies_in_area.size() > 0:
		take_damage(ennemies_in_area[0].get_damage())
	# Get the input direction and handle the movement/deceleration.
	var direction = Vector2(Input.get_axis("ui_left", "ui_right"),Input.get_axis("ui_up","ui_down")).normalized()
	if direction.x:
		velocity.x = direction.x * SPEED * delta
	else:
		velocity.x = move_toward(velocity.x, 0, SPEED*delta)
	if direction.y:
		velocity.y = direction.y * SPEED * delta
	else:
		velocity.y = move_toward(velocity.y, 0, SPEED*delta)
	move_and_slide()
  • Ennemie is a CharacterBody2D with basic movement trying to touch player
func _physics_process(delta) :
	velocity = position.direction_to(player.position).normalized() * BASE_SPEED * _ennemie_speed_percent * delta
	move_and_slide()

Player is on collision layer 1 and collision mask 4 (my map)
Monster is on collision layer 2 and collision mask 2 (ennemie) and 1 (player)

I tried different combos of layer and mask and obtained differents results, and it’s the one that allow players to push ennemie (since he didn’t detect collision with them) but enemies cannot go through the player (allow players to push them)
But this combo has a drawback: player move like ennemie didn’t exist (and that’s because, for him, they didn’t exist since he doesn’t have a mask 2) and feel like my enemies are absolutely weigh less

Options already considered :

I think that if I turn my enemies in RigidBody I will have access to weight and a similar interaction I was looking for, but I want my enemies to be code driven for movement and not physics driven and so CharacterBody2D seem a better choice. Am I wrong ?

Thank you for your time !