Move_and_collide Collisions Not Detecting

Godot Version

Godot 4.2

Question

How do I fix my Asteroids Clone not detecting collisions consistently.

I am making a cleaning-themed clone of the Asteroids arcade game for practice and sometimes the game does not recognize collisions between the bullets and the asteroids. The bullets always register the collision, but the asteroids only register it some of the time.

Useful details(?)

  • I am using GdScript
  • The bullets, asteroids, and player are all CharacterBody 2D’s, with either a square or a circle for its’ collision shape.
  • For all movement and collisions, I am using move_and_collide() and saving the collisions to a variable.
  • The bullets exist on layer 2 are set to only scan for collisions with asteroids, which exist on layer 3 and are set to scan for collisions from bullets and the player which is on layer 1
  • Each object has a block of code it is supposed to run upon collision, being get the collider’s damage value, and pass it to a take_damage function inside the health component.
  • The Collision only seems to be detected on the top and bottom sides of the largest asteroid which uses a square collision shape.

Here’s the _physics_process function all three sizes of asteroid use:

func _physics_process(delta):
	#Move and detect collisions
	velocity = transform.y * speed * delta
	
	var collision = move_and_collide(velocity)
	if collision:
		#Debug print statement
		print("Collision")
		#Pass collider's damage to health component
		var collider = collision.get_collider()
		health.takeDamage(collider.damage)
		#Turn 180 degrees - I may remove this
		rotate(PI)

Thank you for any assistance.

Hey there,
maybe not the answer you are looking for. But you could add an area2d (additional to the character body)to the asteroid. If the area2d does the same problem as the body, you can exclude, that the problem is the body.

Thank you. I will try that out.