Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Using Raycasting to Tell Terrain Materials?

Asked by 6 years ago

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!

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. Garfanzo 30 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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
0
he said he needs it for terrain not parts. wookey12 174 — 6y
0
Whoops, I didn't realize he meant smooth terrain. Operation_Meme 890 — 6y
Ad

Answer this question