What is the issue? I have a random generation script and I want parts to appear at the random position, but they tend to go partially inside the base part. I want to fix that and have the parts on the base part instead.
Here’s the updated code, it works but it’s still a little bit off the ground. How do I fix that?
local function WallsCreation()
local RandomX, RandomZ = math.random(BackSide, FrontSide), math.random(RightSide, LeftSide)
local RandomVector = Vector3.new(RandomX, 100, RandomZ)
local Result = workspace:Raycast(RandomVector, Vector3.new(0, -100, 0))
if Result then
if Result.Instance == Carpet then
local Wall = Assets:WaitForChild("Wall"):Clone()
Wall.Parent = workspace
Wall.Anchored = true
Wall.Position = Result.Position + Vector3.new(0, Result.Position.Y + (Wall.Size.Y/2), 0)
end
end
end
local function WallsCreation()
local RandomX, RandomZ = math.random(BackSide, FrontSide), math.random(RightSide, LeftSide)
local RandomVector = Vector3.new(RandomX, 100, RandomZ)
local Result = workspace:Raycast(RandomVector, Vector3.new(0, -100, 0))
if Result then
if Result.Instance == Carpet then
local Wall = Assets:WaitForChild("Wall"):Clone()
Wall.Parent = workspace
Wall.Anchored = true
Wall.Position = Result.Position + Vector3.new(0, Result.Position.Y + (Wall.Size.Y/2) - (Carpet.Size.Y/2), 0)
Wall.Orientation = RandomOrientations[math.random(1, #RandomOrientations)]
end
end
end
local function WallsCreation()
local RandomX, RandomZ = math.random(BackSide, FrontSide), math.random(RightSide, LeftSide)
local RandomVector = Vector3.new(RandomX, 100, RandomZ)
local Result = workspace:Raycast(RandomVector, Vector3.new(0, -100, 0))
if Result then
if Result.Instance == Carpet then
local Wall = Assets:WaitForChild("Wall"):Clone()
local FixedY = (Result.Position.Y+(Carpet.Size.Y/2)) - (Carpet.Size.Y)
Wall.Parent = workspace
Wall.Anchored = true
Wall.Position = Vector3.new(Result.Position.X, FixedY, Result.Position.Z)
Wall.Orientation = RandomOrientations[math.random(1, #RandomOrientations)]
end
end
end
Is your ground totally flat? In one picture, it looked like one edge of the block was closer to the ground than the other, or maybe it was just an illusion.
I am sure you already said this in the Wall.Position = pos + Vector3.new(0, Wall.Size.Y / 2, 0) that you mentioned earlier so it should work hopefully.