I have a door opening system, that opens doors. And the problem I have is with double doors, it opens the door on the left correctly, but the door on the right swings open the wrong way.
-- Open
DoorOpen:Play()
for _, v in pairs(door:GetChildren()) do
if v.Name == 'Door' then
print('Door found')
local Goal = {CFrame = AllHinges[v.Hinge] * CFrame.Angles(0, -math.rad(100), 0)}
local Tween = TweenService:Create(v.Hinge, TweenInfo.new(0.5, Enum.EasingStyle.Bounce), Goal)
Tween:Play()
end
end
So how can I open both doors correctly based on their current orientation?
The doors have to be named ‘Door’ because at the start I have to go through every building/room and collect the doors from there. Changing the doors names would require me to go through every single models door and changing the name + changing a bunch of the code
What I do on my game is I have a configuration folder for each door and have a number value for a open angle and close angle. So depending on how you want your door to swing it will work however you want. In your door script just read their own values.
I don’t want to have to insert a value into every single door in the game tho. I want a way for the script to just know if the doors on the left or the right based on its position or something
If you were to take your left door, duplicate it, and turn it upside-down so that the front is still facing you, the door would open the right way. The only problem is, the whole model would be upside-down, and the easiest way to fix that is to flip all the decorations to line up with the left door.
If don’t want to manually set values I guess you could check if the hinge is at a negative offset or positive offset from the door’s center position and based on that open it differently.
local function ToggleDoor(Dir)
TweenService:Create(v.Hinge, TweenInfo.new(0.5, Enum.EasingStyle.Bounce), {CFrame = AllHinges[v.Hinge] * CFrame.Angles(0, math.rad(100) * (Dir or 1), 0)}):Play()
end
for _, Object in next, Doors:GetChildren() do
if Object.Name == 'Door' then
ToggleDoor() -- Identify if it's a left or right door and put -1 as a parameter for a left door and 1 as a parameter for the right door
end
end