Hi, all! I'm trying to make a grid building system. I have the bare bones for a proof of concept, but don't know how to compensate for this issue.

Code:

local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local Part = game.Workspace.Part
Mouse.TargetFilter = Part

function Snap(P)
	local X = math.floor(P.X)
	local Y = math.floor(P.Y)
	local Z = math.floor(P.Z)
	Part.Position = Vector3.new(X, Y, Z)
end

RunService.Heartbeat:Connect(function()
	Snap(Mouse.Hit.p)
end)

That works fine putting the block where the mouse points, but how do I get it to not phase into other blocks. Since the position of the part is based on its center point.

Thanks in advance, Tim

2 comments

0

There's actually a guide on how to do this in the blog if you haven't looked already: https://scriptinghelpers.org/blog/creating-a-furniture-placement-system

0

@pidgey with all do respect, I'm simply looking for the mathematical equation.