Don’t round the Y axis to the grid scale. Move the model up by half it’s BoundingSize.Y. the 2nd value returned from GetBoundingBox is the bounding size.
local RS = game:GetService("RunService")
local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
local Part = Instance.new("Part")
Part.BrickColor = BrickColor.Random()
Part.Anchored = true
Part.Parent = workspace
Mouse.TargetFilter = Part
RS.RenderStepped:Connect(function()
Part.CFrame = CFrame.new(Mouse.Hit.Position + Part.Size/2)
end)
make sure you get the position you want it to towards then add the size of the object and divide by 2
I had a feeling something would go wrong here, I rewrote it and used raycasting so I could get the normal of the part your mouse is pointing at, here ya go
now it will calculate the proper plane of every face
local RS = game:GetService("RunService")
local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
local Model = Instance.new("Model")
local Part = Instance.new("Part")
Part.BrickColor = BrickColor.Random()
Part.Anchored = true
Model.PrimaryPart = Part
Part.Parent = Model
Model.Parent = workspace
local IgnoreList = {Model, Player.Character}
local RayParams = RaycastParams.new()
RayParams.FilterDescendantsInstances = IgnoreList
RayParams.FilterType = Enum.RaycastFilterType.Blacklist
local MaxPlaceDistance = 2000
function RayCast()
local MRay = Mouse.UnitRay
local RayResult = workspace:Raycast(MRay.Origin, MRay.Direction.unit * MaxPlaceDistance, RayParams)
if RayResult then
local EndPos = RayResult.Position + (RayResult.Normal * (Model.PrimaryPart.Size*.5))
Model:SetPrimaryPartCFrame(CFrame.new(EndPos))
end
end
game:GetService("RunService").RenderStepped:connect(function()
RayCast()
end)
Hey actually I do have a question, if I wanted to insert a grid how could I pull this off?
EDIT: I don’t mean actually inserting a grid just getting it to move like it.