When moving CharacterBody2D to any kind of collision, the collision shapes overlap each other.

Godot Version

4.6.1

Question

When moving a CharacterBody2D towards a collision, the collision shapes sort of go inside of each other, and when I let go of the key that moves the CharacterBody2D, it snaps the CharacterBody2D out of the other collision.

The code for the player is based on the “dodge the creeps” player code, with the only important difference being an additional move_and_collide() at the end of the movement code.

func _process(delta):
	var movement = Vector2.ZERO
	if Input.is_action_pressed("move_right"):
		movement.x += 1
		$AnimatedSprite2D.flip_h = false
	if Input.is_action_pressed("move_left"):
		movement.x -= 1
		$AnimatedSprite2D.flip_h = true
	if Input.is_action_pressed("move_down"):
		movement.y += 1
	if Input.is_action_pressed("move_up"):
		movement.y -= 1
	
	
	move_and_collide(movement * delta)

I apologize if this is worded really weirdly btw, I couldn’t really think of any other way to put it.

And just to be thorough, here’s a video demonstration of the issue I’m describing.

You should call move_and_collide() from _physics_process(), I think that will fix it. You can keep the Input handling in _process() if you want to, or you can move all that code to _physics_process().

Or try using move_and_slide() instead.