3 rigidodies2D - set different collsion

Godot Version

4.4

Question

I have 3 different rigidbodies:

  • A wall
  • A box
  • A bullet

The wall and bullet does not and should not collide. This is easily solved with the mask

I have this Box object, I move it around and collide/bounce with a wall. This works.

However, I also have ths bullet object. This should collide with the box and change the box color. This works, but the bullet also exhanges momentum with the box and makes it fly around.

I’ve tried making a custom func _on_body_entered(body: Node2D) for the box. and set for the box:

	contact_monitor = true
	custom_integrator = true
	max_contacts_reported = 1
	

but I am not able to ignore the box being accelated by the bullets. I am hoping I could do something like:

box.gd:

 func _on_body_entered(body: Node2D):
    if body.is_bullet:
       self.change_color()
    else if body.is_wall:
       self.bounce()

but it seems like no matter what I do, the box always bounces around

If you don’t need the bullet to move the box around what if you use areas instead

1 Like

Is there a gameplay reason that the bullet has to be a RigidBody2D except when it collides with a box? An Area2D for the bullet would make your life so much easier.

If it has to be rigid in all other situations except this one you could write your own physics integration to ignore bullets (what you try to do now), but that feels like over-engineering. I’d probably add another collision layer just for bullets. You can then turn the mask of on the Rigidbody collider of the box and turn it on on for a new Area2D with the same shape. Another workaround it adding a raycast to the bullet and disabling the bullet’s collider when it’s about to intersect a box.

1 Like

Thank you @paintsimmon ad @Herb. It’s indeed much better to have the bullets as Area2D. Brilliant suggestion