A Godot 4 plugin that detects the kind of surface a player is standing on by inspecting mesh materials.
- Install and enable the plugin.
- Re-import your environment meshes. The plugin will split up any mesh that has
multiple materials and a static
ConcavePolygonShape3Dinto separate collision meshes so that each material corresponds to a separate collision mesh. - Set up a
RayCast3Dnode on your player object. - Use this code in your
_physics_processfunction to get the name of the material the player is standing on:
if raycast.get_collider() is CollisionObject3D:
var material_name: String = Surfaces.detect(raycast.get_collider())
- If you're using Blender, simply add
-colto the name of your mesh object to give it a staticConcavePolygonShape3D. - Add
-convcolto make it aConvexPolygonShape3Dinstead. The plugin does not split up convex meshes, soSurfaces.detectwill instead return the name of the first material on the mesh. - To create a custom collision mesh that's different than the visible mesh, add
a new mesh as a child of the visible mesh and add
-colonlyor-convcolonlyto the name.Surfaces.detectwill search through the parents of the collision mesh until it finds a visible mesh and use that to determine the material.