Hello!
I am currently creating a placement system for fun but I am having this issue where when placing walls, the cylinder to preview the wall placement is always being bumped up a stud or so.
I’ve tried two methods of determining the Y position, both of which have this issue.
First is snapping the cylinder to the actual plot’s Y axis, moving it up half of the plot’s size to account for the plot’s Y size, and then dividing the cylinder’s X axis (X is the vertical axis because cylinders are on the side by default) but it results in the cylinder being bumped up a full stud.
-- Attempt 1
(plot.Position.Y + plot.Size.Y / 2) + (size.X / 2)
Result:
Second attempt was to move the cylinder relative to mouse.Hit, then move it up half of the wall’s height.
-- Attempt 2
vector.Y + (size.Z / 2)
Result:
Here’s my script in case I skipped over something but AFAIK, I am using :ToWorldSpace and :ToObjectSpace properly so I have no idea what is going on
local wallPlacementPart = Instance.new('Part')
wallPlacementPart.CFrame = plot.CFrame
wallPlacementPart.Shape = Enum.PartType.Cylinder
wallPlacementPart.Parent = ignoreParts
wallPlacementPart.Anchored = true
wallPlacementPart.Transparency = .5
wallPlacementPart.Size = Vector3.new(10,0.5,0.5)
local oldWallPlacementPart
local wallPart
local constructWall = false
connections[#connections + 1] = mouse.Move:Connect(function()
local relativeCFrame = plot.CFrame:ToObjectSpace(mouse.Hit)
local snappedPosition = snapVerticalCylinderToIncrement(relativeCFrame.p, wallPlacementPart.Size, 50) -- This is the function in which I was using trial and error with above
local newCFrame = CFrame.new(snappedPosition)
wallPlacementPart.CFrame = plot.CFrame:ToWorldSpace(newCFrame) * CFrame.Angles(0,0,math.rad(90))
wallPlacementPart.Position = checkExceedsPlotBounds(wallPlacementPart.Position) -- This doesn't affect the Y axis.
if constructWall then
wallPart = wallPart or Instance.new('Part')
if wallPart.Parent then
wallPart = wallPart or Instance.new('Part')
else
wallPart = Instance.new('Part')
end
wallPart.Transparency = 0.5
wallPart.Parent = ignoreParts
wallPart.Anchored = true
wallPart.Position = (wallPlacementPart.Position + oldWallPlacementPart.Position) / 2
wallPart.CFrame = CFrame.lookAt(wallPart.Position, wallPlacementPart.Position)
local zVector = (oldWallPlacementPart.Position - wallPlacementPart.Position).Magnitude
local yVector = oldWallPlacementPart.Size.X
local xVector = oldWallPlacementPart.Size.Y
wallPart.Size = Vector3.new(xVector, yVector, zVector)
end
end)
TIA for any help!