CharacterBody2D Not Detecting Collision Properly

Godot Version

v4.2.2.stable.official [15073afe3]

Question

I have a CharacterBody2D (representing a bug) and a RigidBody2D (representing a bird) that need to detect collisions with each other. The CharacterBody2D has the following physics process function:

func _physics_process(delta):
	var collision
	
	if position.distance_to(targetPosition) < 10:
		queue_free()
	else:
		collision = move_and_collide(velocity * delta)

	if collision:
		bugEaten.emit()
		queue_free()

However, while collision seems to be properly detected most of the time, there are occasional moments where the CharacterBody2D will not execute any code in the “if collision” branch, but will still react to the collision by being pushed to the side or by stopping the RigidBody2D’s movement. This is shown in the following video:

I have tried messing with the collision settings on both the CharacterBody2D and the RigidBody2D, but it hasn’t helped. Is there something in the physics process code that is causing this?

you sure no error printed in the debugger console?

it could be just godot engine bug that havent been fixed.
the workaround now is to try make bird also characterbody2d or both rigidbody2d

1 Like

I see no errors in the console. I actually had both as CharacterBody2D in an earlier version of the game, but I changed it in an attempt to solve issues with collisions not being detected properly. I didn’t know this was a known bug though. I suppose I’ll see if it gets fixed in a future version of the engine.

Actually, disabling the collision mask on the bird seems to fix it so far? At least it’s a temporary workaround until the bug gets fixed.