-
I want to make a building mode in my building system where you can place walls glued to each other.
-
The mode works fine until it reaches near the top of other buildings, when it does it starts no-clipping inside of them. It only doesn’t do that when my camera is lower than the building’s top, so I’m guessing it has to do something about the camRay.
How it should look like:
How it looks like:
Do note that it only no-clips when it’s near the top and my camera is higher than the block, if my camera is lower, then it doesn’t no-clip.
- I tried looking through the devforum and tried changing my code a ton of times to fix that, but none of that seemed to work. If I missed a devforum page that went through this, please link it to me.
This is my code:
while equipped and eMode do
RunService.Heartbeat:Wait()
if (mouse.Hit.p - tool.Handle.Position).Magnitude <= 50 then
sticky.BrickColor = BrickColor.new("Bright green")
else
sticky.BrickColor = BrickColor.new("Really red")
end
local camRay = camera:ViewportPointToRay(mouse.X, mouse.Y)
local param = RaycastParams.new()
param.FilterDescendantsInstances = {mouse.Target}
param.FilterType = Enum.RaycastFilterType.Whitelist
local res = workspace:Raycast(camRay.Origin,camRay.Direction*600,param)
if res then
sticky.CFrame = CFrame.new(mouse.Hit.p, mouse.Hit.p + res.Normal)
sticky.CFrame = sticky.CFrame + (sticky.CFrame.LookVector * (sticky.Size.Z/2))
sticky.Orientation = Vector3.new(sticky.Orientation.X,sticky.Orientation.Y,rValue)
else do
sticky.Position = mouse.Hit.p + sticky.CFrame.LookVector * (sticky.Size.Z/2)
end
end
end
Any help is appreciated, thanks.