Hey!
I’m creating a build system where you can select a grid to build on and then use a GUI to select an item from my BuildAssets and place it on the grid, usign R to rotate. My plan is:
ON EACH RENDER / RENDERSTEPPED
- Evaluate a rough position / target from the mouse or Infront of the player.
- Apply the current rotation integer to the model.
- Snap the rotated CFrame to the grid.
- PivotTo / SetPrimaryPartCFrame
Here’s my code snippet (part of a much bigger script):
RunService:BindToRenderStep("PlacementSession", 1, function()
local CFramePosition = Player.Character.PrimaryPart.CFrame
local GridRotation = self.Grid.CFrame.Rotation
local FinalRotation = self.Rotation - GridRotation
-- My desired rotation is self.Rotation (0- 360, it goes up by 90 each time0.
-- I need to change CFramePosition so that it is properly rotated.
self.TransparentModel:SetPrimaryPartCFrame(CFramePosition)
end)
Rotation:
function PlacementSession:rotateDegrees(degreesRotation) : {}
local proposedRotation = self.Rotation + degreesRotation
if proposedRotation > 360 then
local degreesCompensation = math.floor(proposedRotation / 360)
degreesCompensation = degreesCompensation * 360
proposedRotation = proposedRotation - degreesCompensation
end
self.Rotation = proposedRotation
return self
end
-- Literally just grows self.Rotation by the argument and makes sure it's below 360 or it will compensate to make it below 360.
Grid BasePart is accessible through self.Grid, I appreciate any help as I’ve been on this for hours across multiple servers / sites!