I am working on an algorithm and as always, I have problems with CFrames, so:
local function rotatePiece(piece, turningPoint, rotation)
--
if rotation == 0 then return end
--
local newPoints = {}
--
for i, point in piece.points do
--
if point == turningPoint then
newPoints[i] = point
continue
end
--
local targetCFrame = CFrame.Angles(0, math.rad(rotation), 0)
local originCFrame = CFrame.new(turningPoint.x, 0, turningPoint.z)
local pointCFrame = CFrame.new(point.x, 0, point.z)
--
local newCFrame = targetCFrame * originCFrame:ToObjectSpace(pointCFrame)
--
print("--")
--
warn(point.x, point.z)
warn(newCFrame.X, newCFrame.Z)
--
print("--")
--
newPoints[i] = {x = math.round(newCFrame.Position.X), z = math.round(newCFrame.Position.Z)}
--
end
--
piece.points = newPoints
--
end
piece is a combination of points and each point is a table with a x and z value.
the turningpoint is one of the points from the piece where the rotation is based of, in this case its the top left one.
This is what happens with 90 degrees:
This is what normally happens with 0 degrees:
I can provide more things if needed, but I just wanted to keep it short.
Thank you for reading and any help would be much appreciated, have a great day or night!

