The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+4 votes


I have two kinematic bodies (kbody1, kbody2), and both have a collision shape/polygon.
In the world there are other object too (static/rigid bodies), and they also have their own collision polygons.

I want the 2 kinematic bodies to collide with all objects in the world, except each other.

So the main goal is that kbody1 never collide with kbody2.

Is there any way to do this in Godot?

Thank you!

in Engine by (685 points)

3 Answers

+5 votes
Best answer

You could use layers

put kbody1 in layer 1
put kbody2 in layer 2
put everything else in layer 1 and in layer 2

should solve the problem

Incase you don't know where to set then layer this is where;
This is where you find the setting

by (370 points)
selected by

I will try layers, thanks!

But I don't understand your third instruction:

put everything else in layer 1 and in layer 2

How can be an object on two different layers at the same time?

Ahh, I got it!
Looks good! I will try it, and come back!


Problem solved with the layer settings! Thanks again!

Thanks! This worked for me as well. However can you explain what the checkboxes for Layers and Masks mean? I only set the layers in both of my bodies like in the picture.

+6 votes

While I would always recommend using layers as much as possible (since they can improve performance and help avoid bugs) in this case it may be the simpler solution to use the add_collision_exception_with()-method that allows you to specify a physics body that a physics body is supposed to not collide with.

As soon as you have multiple exceptions I would recommend layers, but since this seems to be about one and only one exception this may be easier.

by (1,124 points)

I have multiple exceptions. I just tried to simplify the issue with the 2 bodies.
But good to know that there is another solution, thank you!

+1 vote

You need to use layers and masks, layers are where the objects are detected for collisions and masks where they look for collision.

The idea is to match layer and mask of the monitored and monitoring nodes (to use Area wording)

If your "world" is on layer 1, the special bodies need mask on 1 to detect it.

But you don't want theese bodies detect each other, so they can't be on layer 1, remove all the layers on them.

Now, if your game world or specific parts of it need to detect the special bodies, add layer on 2 to the bodies and mask on 2 to the detecting nodes too.

With 1 and 2 I mean the checkboxes on the inspector, look the docs to see how to use the methods.

ps: as of Godot 2.1.2, the 3D version, KinematicBody, is not using masks, just layers, and Area2D may look for both in some cases, do some tests first.

by (7,890 points)

Thanks for the explanation!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.