Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Using Raycasting to Tell Terrain Materials?

So I am working on an auto-generating minimap for my game that will create itself based on raycasting throughout the map, detecting what it has hit, and placing ImageLabels for the parts it has encountered. So far it is working beautifully, but I do have one problem though, when it hits the terrain I have no way to check what material it has hit, whether it is grass, slate, dirt, etc.

So is it possible to detect the terrain material based on a ray? The line for the ray is very basic, but if you would like to see it then here it is:

local ray = Ray.new(startingPoint, Vector3.new(0, -1500, 0))
local part, endPoint = workspace:FindPartOnRay(ray)

print(part)

and when it hit's terrain it says so, but I don't know how to tell the material of it. Thanks!

1 comment

0

@dragonmaster4111, thank you, but I need this for Terrain, as that is for bricks. But, I think I have it figured out, it took a really deep search in the Wiki, but I found it in a back corner, lol.

1 answer

This is actually very simple. Just do

part.Material

I tested this in one of my places, and it printed: Enum.Material.Plastic.

Example:

local ray = Ray.new(startingPoint, Vector3.new(0, -1500, 0))
local part, endPoint = workspace:FindPartOnRay(ray)

print(part.Material)

if part.Material == Enum.Material.Plastic then
	-- whatever
end

2 comments

0

he said he needs it for terrain not parts.

0

Whoops, I didn't realize he meant smooth terrain.

This discussion is preserved as it was. New answers, comments, and votes are closed.