Placement system rotation problem

I want to have a placement like that in lumber tycoon 2 but I can’t seem to find a way to do it

I used some of the open source placement systems and got it all working but the problem arises when I rotate the part
Here’s the issue
https://cdn.discordapp.com/attachments/1055273954568310844/1059474834251337868/8mb.video-CQl-clMqoAiH.mp4

I tried checking if the rotatevalue is 180 but it does not work either
Script:


local nearestSnap = .5

function roundToNearest(x,num,normal)
	if num == 'x' then
		if normal.X ~= 0 then
			return x else 
			return nearestSnap * math.floor(x / nearestSnap)
		end
	elseif num == 'y' then
		if normal.Y ~= 0 then
			return x else 
			return nearestSnap * math.floor(x / nearestSnap)
		end
	elseif num == 'z' then
		if normal.Z ~= 0 then
			return x else 
			return nearestSnap * math.floor(x / nearestSnap)
		end
	end
end


function Placement:CalcPlacementCFrame(model, positionX,positionY, rotation,turn)

	local unitRay  = workspace.CurrentCamera:ScreenPointToRay(positionX, positionY, 1) --origin, Vector3.new(0, -1, 0));
	local ray = Ray.new(unitRay.Origin, unitRay.Direction * 1000)
	local hit, pos, normal = game:GetService("Workspace"):FindPartOnRay(ray, model)
	local tsize = model.PrimaryPart.Size
	local 
	 	surfacePosition = (tsize*normal/2)

	local finalpos = CFrame.new(pos+surfacePosition)
	local snappedPosition = CFrame.new(
		roundToNearest(finalpos.X,'x',normal), 
		roundToNearest(finalpos.Y,'y',normal),
		roundToNearest(finalpos.Z,'z',normal)
	)
	return snappedPosition* CFrame.Angles(turn, rotation,turn)
end
1 Like

I could be wrong, but I think when you are rotating it and placing it somewhere else, it’s not updating the hitbox, I could be wrong, but a wild guess.

1 Like

oh yeah i guess you’re right it wasn’t updating the hitbox
so how do i make it so that it’s always like this:
image
and not this:
image
(the mouse is pointing on the left surface of the green part)

Are these movable parts made with a union?

No they are models with a primary part in it

You can try this out, it’s my old version of the placement system.
local Plr = game.Players.LocalPlayer
local Mouse = Plr:GetMouse()
local Placement = {}

local Base = {
Type = “BasePart”,
Name = “Base”
}

local Debug = true

local New = {
Type = “Model”,
Name = “New”,
Parent = workspace,
Archivable = true
}

Placement.SpawnPart = Instance.new(Base.Type, New)
Placement.SpawnPart.Name = Base.Name
Placement.SpawnPart.CFrame = CFrame.new()
Placement.SpawnPart.Anchored = true

if Debug then
Placement.SpawnPart.Material = “SmoothPlastic”
end

Placement.SpawnPart.Size = Vector3.new(1,3,1)
Placement.SpawnPart.TopSurface = “Smooth”
Placement.SpawnPart.BottomSurface = “Smooth”

local XZRay = Ray.new(Vector3.new(),Vector3.new())
local XYRay = Ray.new(Vector3.new(),Vector3.new())
local YZRay = Ray.new(Vector3.new(),Vector3.new())

local XZPos = nil
local XYPos = nil
local YZPos = nil

local function Clamp(V,Low,High)
return math.max(Low,math.min(High,V))
end

local function GetPosition(Ray,Model)
local X,Y,Z = Mouse.Hit.x,Mouse.Hit.y,Mouse.Hit.z
if Ray.Direction.x ~= 0 then
X = Model.PrimaryPart.Position.x
end
if Ray.Direction.y ~= 0 then
Y = Model.PrimaryPart.Position.y
end
if Ray.Direction.z ~= 0 then
Z = Model.PrimaryPart.Position.z
end
return Vector3.new(X,Y,Z)
end

local

1 Like

sorry to say but it did not help the problem at all