I have a robot, that is a CharacterBody3D, with a RayCast3D attached.
I have walls, that are 3d staticbodies.
I have pickups, that are 3d staticbodies.
I want the robot to collide with the walls, but not the pickups.
I want the raycast to collide with walls and the pickups.
I assumed that I should put the robot and walls in layer 1 and collisionmask to layer 1, the pickups in layer 2 and collisionmask to layer 2, and set the raycast collisionmask to both layers.
Thats not working, the rays collide with walls but not pickups.
How do I do this?
How do I use collision masks?
- Edited
An approach I've used:
For each type of object:
Specify its collision layer as a power of 2:
object type A: layer 1
object type B: layer 2
object type C: layer 4
object type D: layer 8
object type E: layer 16
Specify its collision mask as the sum of the collision layers of the object types with which it can collide:
object type A: mask 2 + 16 = 18 (can collide with object types B and E)
object type B: mask 1 + 8 = 9 (can collide with object types A and D)
object type C: mask 4 (can collide with object type C)
object type D: mask 2 (can collide with object type B)
object type E: mask 1 (can collide with object type A)
I haven't used raycasts (successfully). I don't know if they handle collisions differently than other nodes.
Gamero I have pickups, that are 3d staticbodies.
no. static bodies are static. use them for the world.
for pickups use either RigidBody3D
or Area3D
Gamero I want the robot to collide with the walls, but not the pickups.
I want the raycast to collide with walls and the pickups.
I assumed that I should put the robot and walls in layer 1 and collisionmask to layer 1, the pickups in layer 2 and collisionmask to layer 2, and set the raycast collisionmask to both layers.
Thats not working, the rays collide with walls but not pickups.
How do I do this?
world on layer 1, collide with doesn't matter
player on layer 2, collide with layer 1 (this means it can walk and hit walls)
pickups on layer 3, (collide with layer 4?). collide with layer 2 will make them be moved by the player but the player will not react to them.
raycast on layer 4, collide with layer 3. if you are using an Area3D
you have to enable detect areas.
Cant get it to work. I tried setting up 4 layers like you wrote, and changed the pickups to area3ds, and set the raycast to detect areas.
As soon as I turn off layer 1 for the pickups, the raycast stops detecting them.
Here is how I set up the pickups (scraps)
`SetCollisionLayerValue(tacticalScene.COLLISION_LAYER_STATIC, false);
SetCollisionLayerValue(tacticalScene.COLLISION_LAYER_DRONE, false);
SetCollisionLayerValue(tacticalScene.COLLISION_LAYER_SCRAP, true);
SetCollisionLayerValue(tacticalScene.COLLISION_LAYER_RAYCAST, false);
SetCollisionMaskValue(tacticalScene.COLLISION_LAYER_STATIC, false);
SetCollisionMaskValue(tacticalScene.COLLISION_LAYER_DRONE, false);
SetCollisionMaskValue(tacticalScene.COLLISION_LAYER_SCRAP, false);
SetCollisionMaskValue(tacticalScene.COLLISION_LAYER_RAYCAST, true);`
and I set up the raycast like this
rayCast.SetCollisionMaskValue(tacticalScene.COLLISION_LAYER_STATIC, true);
rayCast.SetCollisionMaskValue(tacticalScene.COLLISION_LAYER_DRONE, true);
rayCast.SetCollisionMaskValue(tacticalScene.COLLISION_LAYER_SCRAP, true);
rayCast.SetCollisionMaskValue(tacticalScene.COLLISION_LAYER_RAYCAST, true);
Any help debugging this is appreciated.
- Edited
Gamero this is from my own project:
RAYCAST
AREA2D
Gamero As soon as I turn off layer 1 for the pickups, the raycast stops detecting them.
don't change this in code
collision layer is the layer the object is in. collide with/mask is the objects it will collide with.
if player is in layer 2, world in layer 1, and a ball in layer 3. if the ball has collide with layer 2 and layer 1, it will be stopped by the walls and floor and moved by the player. but player has collide with layer 1 only, so it will not react to the ball.
trizZzle RayCast Mask: 15
@Jesusemora All of the nodes are procedurally generated, so I think I have to set it in code.
Thanks for the clarification of how the layers work. It is how I suspected it works, but I was not certain.