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!
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