I’m creating a placement system and it’s taken me ages to get this far, for the most part the objects have been fine however now I’m trying to implement walls that are 5, 15, 0.5 in size are they appear to only rotate 2 directions.
Although my other items rotate all 4 directions as shown below.
There is a TON of code but here’s the rotation
For reference the GRID_UNIT is 5 meaning these tiles are 5 studs large, The Spawner item in the video is a 10x20 hitbox and the walls are 0.5x5
I have tried both my normal rotate and the “Smart Rotate” function and either way the walls rotate 2 directions
-- Handles rotation of the model
local function ROTATE(actionName: string, inputState: Enum.UserInputState, inputObj: InputObject?)
if not (currentState ~= 4 and currentState ~= 2 and inputState == Enum.UserInputState.Begin) then return end
if smartRot then
-- Rotates the model depending on if currentRot is true/false
if currentRot then rotation += rotationStep; else rotation -= rotationStep end
print(rotation)
else
rotation += rotationStep
end
-- Toggles currentRot
local rotateAmount = round(rotation/90)
currentRot = rotateAmount%2 == 0 and true or false
if rotation >= 360 then rotation = 0 end
if preferSignals then rotated:Fire() end
end
This is the snapping and plot clamping functions I’m using
-- Clamps the x and z positions so they cannot leave the plot
local function bounds(c: CFrame, offsetX: number, offsetZ: number): CFrame
local pos: CFrame = plot.CFrame
local xBound: number = (plot.Size.X*0.5) - offsetX
local zBound: number = (plot.Size.Z*0.5) - offsetZ
local newX: number = clamp(c.X, -xBound, xBound)
local newZ: number = clamp(c.Z, -zBound, zBound)
local newCFrame: CFrame = cframe(newX, 0, newZ)
return newCFrame
end
-- Returns a rounded cframe to the nearest grid unit
local function snapCFrame(c: CFrame): CFrame
local offsetX: number = (plot.Size.X % (2*GRID_UNIT))*0.5
local offsetZ: number = (plot.Size.Z % (2*GRID_UNIT))*0.5
local newX: number = round(c.X/GRID_UNIT)*GRID_UNIT - offsetX
local newZ: number = round(c.Z/GRID_UNIT)*GRID_UNIT - offsetZ
local newCFrame: CFrame = cframe(newX, 0, newZ)
return newCFrame
end
If there is something else I should post to improve my chances of getting help just ask