How would I make grass a single layer

Hi, Im doing a map generation thing. The blocks types are based of what height it reaches, however this can cause some problems


How would I make the grass a single layer?

local function GetBlockType(Height,QuartzPercentage,MulchPercentage)
	local blockType = nil

	if Height >= 48  then
		blockType = partClass.Grass
	elseif Height <= 25 then
		blockType = partClass.Rock

		if QuartzPercentage == 1 then
			blockType = partClass.Quartz
		end
	else
		blockType = partClass.Dirt
		if MulchPercentage == 1 then
			blockType = partClass.Mulch
		end
	end

	return blockType
end

You could use raycasts to see if there is a block above the current block and if there is then spawn dirt else grass.

How would i check if there isnt something above the block?

When you raycast, you need to check if you had a result, if not, then theres nothing above.

if not raycastResult then
1 Like

Hi, for some reason this does this


i dont know what im doing wrong

					local origin = dirt.Position
					local direction = (dirt.Position + Vector3.new(0,2556,0)) - dirt.Position

					local raycast = workspace:Raycast(origin,direction,params)
					if raycast then
						local distance = (origin - raycast.Position).Magnitude
						local inst = raycast.Instance
						if inst:IsA('BasePart') then
							if inst.Name == 'Dirt' or inst.Name == 'Mulch' then
								return 
							end
						end
					elseif not raycast then
						local grass = partClass.Grass.Part:Clone()
						grass.Position = dirt.Position + Vector3.new(0,grid,0)
						grass.Orientation = dirt.Orientation
						grass.Parent = workspace.Map[grass.Name]

Why are you adding dirt.Position in direction!? Stop that. Direction is a vector not a point. Do:

Direction = Vector3.new(0,10,0)

I kinda got it working butttt

Hm… why not just make a ray or if you are using a table then use that to see if the block down is a grass block or no, if it is then return.

sorry what do you mean by this?

Basically just see if the block below is grass or not.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.