How do I get raycasts to recognize different layers within a gridmap?

Godot Version

v4.1.2.stable.official [399c9dc39]


I’m working with a 3D gridmap that contains some level geometry assets. I’m using four raycasts and checks to detect ledges and 45 degree slopes. Originally I had the stair collision geometry 1 to 1 with its shape, but I’ve switched them to 45 degree slopes because it’s easier to code.

In the image above, you can see the collision geometry and you can see that I’ve put the stair object on layer 2. All other objects are layer 1. the problem is that the gridmap itself is on layer 1

Is there a way I can get my player raycasts to differentiate between gridmap objects on layer 1 and layer 2? I’ve tried researching but I’m drawing up blanks.

and if not that, how can I get my collision detection code to differentiate between a 45 degree sloped object that is a slope and a 45 degree sloped object that is a staircase?

You can cast rays at both layers by adding the masks together logical additions layer1 | layer2, now to differentiate you may need to look at the collided body collision layer. Or you can cast two rays with separate collision layer masks, and not need to do the extra ifs to check a bodies collision layer.

There are two ways to cast rays…

Easier node based:

GridMap places and combines MeshLibrary item shapes used in the cells by quadrant. They do not exist as an individual physics body with its own collision mask so you can not ray hit them as an individual object.

What you export from your scene to a MeshLibrary stops to exist as an individual node. The MeshLibrary only parsed the mesh data, collision shapes and navigation polygons, everything else from the nodes is not used because it does not exist in a MeshLibrary.