Alright so I’m working on this placement system to learn more about it, I have couple problems I want to solve that I couldn’t find on other topics but I hope this one will help and will sure help others having the same issue
With the current placement system that I created using mouse and raycast I don’t really know how I would implement increment system so it’s smoother to build and not have a messy crap that isn’t lined up. Here’s a video:
I also have another problem that I don’t know how to make model be flat on the surface and not go through (also so it doesn’t rotate), I don’t know how to explain it but here’s a video:
Try this:
If the placing block is on another placed block, get the height of the placed block, then do something like placing block.Position.Y = placing block.Position.Y - placed block.Position.Y. I am not sure, this is the only solution I can think of.
To avoid any unexpected rotation you should work only with Position (not with the whole CFrame). To keep it aligned, the simplest way is to round to the desired integer.
Here I restrict it to 1 stud
while true do
task.wait()
local raycastparams = RaycastParams.new()
raycastparams.FilterType = Enum.RaycastFilterType.Blacklist
raycastparams.FilterDescendantsInstances = {player.Character, blocting}
raycastparams.IgnoreWater = true
local posting = workspace.CurrentCamera:ScreenPointToRay(mouse.X, mouse.Y)
raycasthit = workspace:Raycast(posting.Origin, posting.Direction * 300, raycastparams)
if raycasthit then
blocting.Position = Vector3.new(math.floor(raycasthit.Position.X), math.floor(raycasthit.Position.Y) + blocting.Size.Y/2, math.floor(raycasthit.Position.Z))
end
end
Ok. Usually in a positioning system we handle Models. Then we simply use the MoveTo method.
Here I change blocting to a model
if raycasthit then
local pos = Vector3.new(math.floor(raycasthit.Position.X), math.floor(raycasthit.Position.Y) + blocting.PrimaryPart.Size.Y/2, math.floor(raycasthit.Position.Z))
blocting:MoveTo(pos)
end