I had issues with actually getting the perfect number to make the EndConnection of the previous tile and the StartConnection of the new tile / object align.
Here is an example of some connections if that helps:
Previous tile:
StartConnection = “Front”,
EndConnection = “Right”,
To place tile (new):
StartConnection = “Front”,
EndConnection = “Back”,
How it looks like:
How it’s supposed to look like:
Get the start and end connections for the old tile and another two for the new tile, and do this formula: (endDegree - startDegree) % 360, (get the degrees from the table of degrees you already have) and you should get the rotation angle:
local degrees = {
["Front"] = 0,
["Left"] = 270,
["Back"] = 180,
["Right"] = 90,
}
function RotateAngle(startConnection, endConnection)
local startDegree = degrees[startConnection]
local endDegree = degrees[endConnection]
local rotateAngle = (endDegree - startDegree) % 360
return rotateAngle
end
-- Example use:
local oldTile = {
StartConnection = "Front",
EndConnection = "Right"
}
local newTile = {
StartConnection = "Front",
EndConnection = "Back"
}
local rotateAngle = RotateAngle(oldTile.EndConnection, newTile.StartConnection)
print("Rotation Angle: " .. rotateAngle)
local function RotateAngle(startConnection, endConnection)
local startDegree = directions.Degrees[startConnection]
local endDegree = directions.Degrees[endConnection]
local rotateAngle = (endDegree - startDegree) % 360
return rotateAngle
end
local newRotation = RotateAngle(previousBackEnd, selectedFrontEnd)
local function RotateAngle(startConnection, endConnection)
local startDegree = directions.Degrees[startConnection]
local endDegree = directions.Degrees[endConnection]
local rotateAngle = (endDegree - startDegree) % 360
local negativeAdd = 0
if rotateAngle < 0 then
negativeAdd = 360
end
return rotateAngle + negativeAdd
end
Yea so… Any ideas why it couldn’t work? Maybe it would be a good idea to step away from that degrees table and just find a way to make the back end of old tile and front end of new tile align?