How do I detect what material (wood, plastic etc.) a player is walking on or what terrain type they are walking on?
2 Likes
player.Character.Humanoid.FloorMaterial
2 Likes
Humanoid.FloorMaterial
returns the material
1 Like
Alternatively you could use ray casting. ray casting is more reliable and you can also check what material is under the player even if they’re still in the air. (You can also check in all directions too)
A quick example would be
local Player = game.players.LocalPlayer
local Character = Player.Character or Character.Added:Wait()
local HRP = Character:FindFirstChild(“HumanoidRootPart”)
while true do
task.wait(1)
Local RayParam = RaycastParams.new()
RayParam.FilterDescendantsInstance = {Character}
local ray = workspace:Raycast(HRP.Position,HRP.CFrame.UpVector * -10,RayParam)
if ray then — if the ray hit a object
local Material = ray.Instance.Material
if Material == Enum.Material.Grass then
print(“Player is on grass!”)
end
end
end
I have not tried this out so there may be a typo
3 Likes