I want to place stairs based on direction I face, and set various models based on this info
As you can see, first placement is right, but second placement creates a corner stair, when I need the already placed stair to be changed. I know why this is occuring, but unsure of the math and best way to detect exactly what needs to changing when/where.
The code below is really clunky and makes things very difficult to debug
if StairLookVector.X == 1 then
if RaycastLookVector.Z == 1 then
CurrentStyle, CurrentAngle = "Corner", CFrame.Angles(0, 0, 0)
elseif RaycastLookVector.Z == -1 then
CurrentStyle, CurrentAngle = "Corner", CFrame.Angles(0, math.rad(90), 0)
end
elseif StairLookVector.X == -1 then
if RaycastLookVector.Z == 1 then
CurrentStyle, CurrentAngle = "Corner", CFrame.Angles(0, math.rad(90), 0)
elseif RaycastLookVector.Z == -1 then
CurrentStyle, CurrentAngle = "Corner", CFrame.Angles(0, 0, 0)
end
elseif StairLookVector.Z == 1 then
if RaycastLookVector.X == 1 then
CurrentStyle, CurrentAngle = "Corner", CFrame.Angles(0, math.rad(90), 0)
elseif RaycastLookVector.X == -1 then
CurrentStyle, CurrentAngle = "Corner", CFrame.Angles(0, 0, 0)
end
elseif StairLookVector.Z == -1 then
if RaycastLookVector.X == 1 then
CurrentStyle, CurrentAngle = "Corner", CFrame.Angles(0, 0, 0)
elseif RaycastLookVector.X == -1 then
CurrentStyle, CurrentAngle = "Corner", CFrame.Angles(0, math.rad(90), 0)
end
end
local Degrees = GetCardinalDirection(cameraCFrame)
local PlacementCFrame = CFrame.new(RoundPosition) * Degrees
local StairDesign, StairRotation = DoCasts(PlacementCFrame)
local Part = ReplicatedStorage[StairDesign]:Clone()
Part:PivotTo(PlacementCFrame * StairRotation)