#How to get the collision layer of a TileMap from a ray or shape cast

4 messages · Page 1 of 1 (latest)

timid prairie
#

I'm making a platformer and I want to apply friction to the player based on the surface they're standing on. I've set up 2 collision layers 17 and 18 and I have a raycast that points down, to hopefully check what kind of ground we're on.

I can't seem to figure out how to get the layer of the tile from it though.

The use of GetCollisionMaskValue doesn't work since it returns true for both, even if the tile beneath us is definitely only one type.

Is there a way to get only what's directly underneath us using a raycast?

        if (groundCast.IsColliding())
        {
            //both of these are printed because the tilemap technically has "both" types. 
            if (groundCast.GetCollisionMaskValue(17))
            {
                GD.Print("On Normal Terrain");
            }
            if (groundCast.GetCollisionMaskValue(18))
            {
                GD.Print("Slippery Terrain");
            }
        }

Any help is appreciated.

timid prairie
#

I'll add I do know I could make 2 Different tile maps, and then separate them, but I'd like to avoid having to maintain multiple different tilemaps for my own sanity

keen herald
#

maybe you should use custom data for that instead of layers

#

can create a custom data called surface_type and paint it on different tiles