Howdy!
I’m making a sci-fi style door that opens in a pretty fancy way.
Pretty cool!
I’ve been trying to figure out how to make the movement of my doors scalable in regards to rotation. Currently if my door is rotated on any axis it will not function properly, and the parts will not tween correctly, as I do not fully understand the maths.
I originally went to tackle this problem using Prismatic Constraints but the documentation is a bit lacking, and I am fairly sure it wasn’t going to work for my anchored door parts. Instead I’ve been trying to use TweenService as my doors will be stationary once placed.
Currently my door opening script is like so:
local function tweenDoor(moving)
for i, v in pairs (moving.Str:GetChildren()) do
local newCF = v.CFrame
if v.Name == "WedgeBR" then
newCF = v.CFrame + Vector3.new(-6.5, 0, 0)
elseif v.Name == "WedgeLB" then
newCF = v.CFrame + Vector3.new(0, 6.5, 0)
elseif v.Name == "WedgeRT" then
newCF = v.CFrame + Vector3.new(0, -6.5, 0)
elseif v.Name == "WedgeTL" then
newCF = v.CFrame + Vector3.new(6.5, 0, 0)
end
ts:Create(v, tweenInfoSlide, {["CFrame"] = newCF}):Play()
end
for i, v in pairs (moving.Ang:GetChildren()) do
local newCF = v.CFrame
if v.Name == "WedgeBL" then
newCF = v.CFrame + Vector3.new(-4.875, 3.5, 0)
elseif v.Name == "WedgeLT" then
newCF = v.CFrame + Vector3.new(3.5, 4.875, 0)
elseif v.Name == "WedgeRB" then
newCF = v.CFrame + Vector3.new(-3.5, -4.875, 0)
elseif v.Name == "WedgeTR" then
newCF = v.CFrame + Vector3.new(4.875, -3.5, 0)
end
ts:Create(v, tweenInfoSlide, {["CFrame"] = newCF}):Play()
end
end
Needless to say this is some pretty cursed code that will break with any slight variation. I’m pretty awful with CFrame maths, I know the distances I want to move each part in relation to their starting point (as shown in the code), I just can’t figure out how to then translate that movement depending on how the door is rotated.
Help?
In case you were wondering, this is how my door opens at any rotation: