Hello there!
Recently (today) i realised my placement system was jittering. It didn’t jitter yesterday or anytime before today… it does jitter in the old versions as well though.
local function renderPreview()
if cannotMovePart then return end
if game.Players.LocalPlayer:GetAttribute("Device") == "PC" and preview ~= nil then
plrgui.PlacementTooltip.Main.Visible = true
plrgui.PlacementTooltip.Main.Position = UDim2.fromOffset(game.Players.LocalPlayer:GetMouse().X - 5,game.Players.LocalPlayer:GetMouse().Y)
else
plrgui.PlacementTooltip.Main.Visible = false
end
local mouseLoc = nil
if game.Players.LocalPlayer:GetAttribute("Device") == "Mobile" then
mouseLoc=latestClickPos
else
mouseLoc = UIS:GetMouseLocation()
end
local cast=nil
local unitRay=nil
if mouseLoc then
unitRay = camera:ViewportPointToRay(mouseLoc.X,mouseLoc.Y)
cast = workspace:Raycast(unitRay.Origin,unitRay.Direction * 1000,castParams)
end
if cast and preview and preview.Parent and mouseLoc and unitRay then
local snapped = placementValidator.SnapToGrid(cast.Position)
local normalcf = CFrame.lookAlong(cast.Position,cast.Normal)
local relsnap = normalcf:PointToObjectSpace(snapped)
local xVector = normalcf:VectorToWorldSpace(Vector3.xAxis*-math.sign(relsnap.X))
local yVector = normalcf:VectorToWorldSpace(Vector3.yAxis*-math.sign(relsnap.Y))
local cf = CFrame.fromMatrix(snapped,xVector,yVector,cast.Normal)
preview.Position = cf:PointToWorldSpace(preview.Size/2)--extraCf.Value + cf:PointToWorldSpace(preview.Size/2)
if preview:GetAttribute("Material") == nil then
preview.Material = if _G.ChosenMaterial then Enum.Material[_G.ChosenMaterial] else game.ReplicatedStorage.Assets:FindFirstChild(preview.Name,true).Material --Enum.Material.SmoothPlastic
end
end
end
game:GetService("RunService"):BindToRenderStep("Preview",Enum.RenderPriority.Input.Value,renderPreview)
I was not the one doing all the math behind this - pretty sure i got it from some youtube tutorial. Its especially jittering on the Y axis where it’s going under the floor
If you guys have any idea on how I can solve this it will be appreciated! : )
Thanks!