Terrain is not being detected by Raycast()

The title basically sums it up. Can I somehow fix this?

local function Draw(value, x, y)
	local Position = Origin + 4 * Vector3.new(x - 1, 0,  y - 1)
	local Height = 4 * 75 * HeightFall(math.min(1, value + .1))
	Height = math.max(Height, 4)
	if value < -.1 then
		Terrain:FillBlock(Position, Vector3.new(4,4,4), Enum.Material.Water)
		return
	elseif value < 0 then
		Terrain:FillBlock(Position, Vector3.new(4,Height,4), Materials[1])
		return
	end
	
	Terrain:FillBlock(Position, Vector3.new(4,Height,4), Materials[3])
	local ray = workspace:Raycast(Position.Position + Vector3.new(0,1000,0), Vector3.new(0, -100000, 0))
	local hitpos = ray.Position - Vector3.new(0, 2, 0)
	hitpos = CFrame.new(hitpos.X, hitpos.Y, hitpos.Z)
	if value < .4 then
		Terrain:FillBlock(hitpos, Vector3.new(4,4,4), Materials[2])
	elseif value < .6 then
		Terrain:FillBlock(hitpos, Vector3.new(4,4,4), Materials[3])
	else
		Terrain:FillBlock(hitpos, Vector3.new(4,4,4), Materials[4])
	end
end

You could use Terrain:ReadVoxels at the position that the Ray hits the terrain, using a region consisting of a single cell then you can read off the material property.

Do you mean reading until it detects something? I really do not need the material.

Also, the documentation states that it is supposed to detect terrain. Is there any reason it is not?

The RaycastResult literally has Material property.

Oh my! Deepest apologies, I truly thought you meant detecting the material.

1 Like