How to get individual doors to open on different axis

I need to have both doors open, but swing open different ways (right now, all doors swing open to the left)

The door on the right should swing open to the right


Example of a building with only 1 door

How I lay out the ‘Door’. The model contains all the vital stuff, so the 2 Door parts are each individual Door, Light is behind the doors, and used to teleport the player, and TeleportPoint is where they get teleported too

-- Open/close the CurrentDoor
local function NearestDoorChanged(door)
	if not CurrentDoor then
		CurrentDoor = door
	end

	if door then		
		-- Open
		DoorOpen:Play()
		
		for _, v in pairs(door:GetChildren()) do
			if v.Name == 'Door' then
				local Goal = {CFrame = v.Hinge.CFrame:ToWorldSpace(CFrame.Angles(0, -math.rad(100), 0))}
				
				local Tween = TweenService:Create(v.Hinge, TweenInfo.new(0.5, Enum.EasingStyle.Bounce), Goal)
				
				Tween:Play()
				
				if v.Parent ~= CurrentDoor then
					-- Close the original door (resets the door position if player enters)
					for _, v in pairs(CurrentDoor:GetChildren()) do
						if v.Name == 'Door' then
							local Goal = {CFrame = v.Hinge.CFrame:ToWorldSpace(CFrame.Angles(0, math.rad(100), 0))}
							
							local Tween = TweenService:Create(CurrentDoor.Hinge, TweenInfo.new(0.5), Goal)
						
							Tween:Play()
						end
					end
				end
			end
		end
	else
		if DoorIsLocked then
			DoorIsLocked = false
			
			return
		end
		
		-- Close
		for _, v in pairs(CurrentDoor:GetChildren()) do
			if v.Name == 'Door' then
				local Goal = {CFrame = v.Hinge.CFrame:ToWorldSpace(CFrame.Angles(0, math.rad(100), 0))}
			
				local Tween = TweenService:Create(v.Hinge, TweenInfo.new(0.5), Goal)
				
				Tween:Play()
			end
		end
	end
	
	CurrentDoor = door
end

-- Find the door that is nearest to the player
local function GetNearestDoor()
	local Character = Player.Character
	if not Character then return end
	
	local HumanoidRootPart = Character:FindFirstChild('HumanoidRootPart')
	if not HumanoidRootPart then return end
	
	local MinDistance, Door = 8, nil
	
	for _, v in pairs(AllDoors) do
		local Distance = (v.Position - HumanoidRootPart.Position).Magnitude
		if Distance < MinDistance then
			MinDistance, Door = Distance, v.Parent.Door
		end
	end
	
	return Door
end

Only pasted chunks of the code, as it’s probably too long to read and fully understand, so just kept the vital stuff for now

1 Like

Edit

CFrame.Angles(x, y, z) 

to your expected axis.

I recommend you add math.rad(num) in the X, Y, and Z of CFrame.Angles(), Angles() uses radians, and math.rad(x) can convert degrees into radians.

You obviously didn’t read my question :roll_eyes:

I already do

local Goal = {CFrame = v.Hinge.CFrame:ToWorldSpace(CFrame.Angles(0, -math.rad(100), 0))}

The problem is that only works for doors on the left. What about doors on the right? I need it to automatically detect the doors position and rotate based on that. Editing the math.rad() here would ruin the doors on the left animation

1 Like

Hi. Having the same issue. Did you ever figure this out? Thanks.

Don’t bump the topic 6 months ago.
Create a new topic.