Advanced Interactive Door Controller (Physics-Based, Customizable.)

Hey everyone!

I’ve always found most doors people make in Roblox to be a bit bland or boring. A game that’s always intrigued me was Amnesia and how they handle doors, along with a few other games that really focus on that physical interaction. I wanted to bring that feeling into Roblox.

What I really wanted to capture was that physical connection. Not just a door that opens when you click it, Or that You just simply walk near and it opens. but one you can actually feel. So to add this “feeling”, you’ll notice a slight initial resistance when you first start dragging, as if you’re overcoming a latch. After that “pop,” the door swings freely, its momentum dependent entirely by how you move your mouse. You can gently nudge it open or throw it wide with a flick of the wrist.

My goal was to create something that’s easy to add to your projects, clean, and just feels nice to use.


RBXL File

DoorController.rbxl (62.4 KB)


Showcase


Features

  • Mouse-Driven Control
    The mouse is used to open the door, allowing for a large amount of control over its speed and momentum. Push it slow, or fling it open.

  • Realistic, And Customizable Physics
    With how the script is designed, you can easily add or manipulate the settings for every door. You can conjure heavy wooden doors that swing slowly, light screen doors that you’d see outside of your patio, and so on, all by changing a few attributes.

  • Simple Tag-Based Setup
    You can very easily add doors via a CollectionService tag.
    Note: As of now, the script tracks a single tagged Part to handle the physics. For detailed doors, simply create your door model and weld all its pieces to the Tagged Part.

  • Built-in State Management
    The script sets an Attribute on the Player object, making it super easy for your other scripts (like a custom camera) to know when the player is busy dragging a door.


How to Set It Up

It’s pretty straightforward:

  1. Place the Script: Put the LocalScript provided below into StarterPlayer > StarterPlayerScripts.

  2. Create the BindableEvent. In ReplicatedStorage Create a BindableEvent with the name InteractionStateChanged

  3. Prepare Your Door Part:

  • Your door’s physics will be controlled by a single Part. This part must be anchored.

  • Using the Tag Editor (under the View tab), give this main door Part the tag: InteractiveDoor .

  • Inside this main part, place an Attachment and name it Pivot . This attachment defines the hinge, so position it exactly where you want the door to rotate from.

  • For detailed doors: If your door is made of multiple parts, weld them all to this main Part. Think of this part as the physics core of your door, All Connected pieces must be unanchored.

That’s it! The script will automatically find any tagged doors and make them interactive.


Customization (via Attributes)

You can customize each door individually by adding Attributes to the main tagged Part. If an attribute isn’t found, it will use the default value from the script.

Attribute Name Type Description Default Value
Sensitivity Number Controls how mouse movement affects door speed. 0.02
MinAngle Number The angle of the door when fully closed. 0
MaxAngle Number The angle of the door when fully open. 90
Damping Number How quickly the door loses momentum. 0.92
SpringStiffness Number How “bouncy” the door is at its limits. 0.1
SpringDamping Number How quickly the “bounce” effect fades. 0.2
AutoClose Boolean If true, the door will automatically swing shut. false
CloseThreshold Number Angle range that triggers the AutoClose feature. 8
OpenSoundId Number Sound ID for when the door starts to open. 9114142598
CloseSoundId Number Sound ID for when the door latches shut. 9114142417
TravelSoundId Number Looping sound ID for when the door is swinging. 19005322750

The Script


local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local CollectionService = game:GetService("CollectionService")

local DoorTag = "InteractiveDoor"
local AngleTolerance = 1.0
local VelocityTolerance = 0.1
local LatchSpeed = 0.15

local DefaultConfig = {
	Sensitivity = 0.02,
	MinAngle = 0,
	MaxAngle = 90,
	Damping = 0.92,
	SpringStiffness = 0.1,
	SpringDamping = 0.2,
	OpenSoundId = 9114142598,
	CloseSoundId = 9114142417,
	TravelSoundId = 19005322750,
	AutoClose = false,
	CloseThreshold = 8,
}

local player = Players.LocalPlayer
local mouse = player:GetMouse()
local doorStates = {}
local activeDoor = nil
local lastMousePosition = nil
local previousMouseBehavior = nil

local function lerp(a: number, b: number, t: number): number
	return a + (b - a) * t
end

local function endInteraction()
	if not activeDoor then return end

	if previousMouseBehavior then
		UserInputService.MouseBehavior = previousMouseBehavior
	end

	local state = doorStates[activeDoor]
	if state then
		state.isDragging = false
	end

	activeDoor = nil
	lastMousePosition = nil
	previousMouseBehavior = nil

	player:SetAttribute("InteractionState", "Default")
end

local function setupDoor(door: BasePart)
	if doorStates[door] then return end

	local pivotAttachment = door:WaitForChild("Pivot", 5)
	if not pivotAttachment then
		warn("InteractiveDoor '" .. door.Name .. "' is missing a 'Pivot' attachment and will not work.")
		return
	end

	local config = {}
	for key, value in pairs(DefaultConfig) do
		config[key] = door:GetAttribute(key) or value
	end

	local sounds = {
		Open = Instance.new("Sound"),
		Close = Instance.new("Sound"),
		Travel = Instance.new("Sound"),
	}
	sounds.Open.SoundId = "rbxassetid://" .. config.OpenSoundId
	sounds.Close.SoundId = "rbxassetid://" .. config.CloseSoundId
	sounds.Travel.SoundId = "rbxassetid://" .. config.TravelSoundId

	sounds.Travel.Looped = true
	sounds.Travel.Volume = 0
	sounds.Travel.PlaybackSpeed = 1

	for _, sound in pairs(sounds) do
		sound.Parent = door
	end
	sounds.Travel:Play()

	doorStates[door] = {
		config = config,
		sounds = sounds,
		state = "CLOSED",
		isDragging = false,
		currentAngle = 0,
		currentVelocity = 0,
		initialPivotCFrame = pivotAttachment.WorldCFrame,
		initialDoorOffset = pivotAttachment.WorldCFrame:Inverse() * door.CFrame,
	}
end

local function onDoorRemoved(door: BasePart)
	if door == activeDoor then
		endInteraction()
	end

	if doorStates[door] then
		for _, sound in pairs(doorStates[door].sounds) do
			sound:Destroy()
		end
		doorStates[door] = nil
	end
end

local function onRenderStep(deltaTime: number)
	for door, state in pairs(doorStates) do
		local config = state.config
		local absVelocity = math.abs(state.currentVelocity)

		if state.isDragging and lastMousePosition then
			local currentMousePosition = UserInputService:GetMouseLocation()
			local mouseDeltaY = currentMousePosition.Y - lastMousePosition.Y
			local impulse = -mouseDeltaY * config.Sensitivity
			state.currentVelocity += impulse
			lastMousePosition = currentMousePosition
		end

		if state.currentAngle > config.MaxAngle then
			local displacement = state.currentAngle - config.MaxAngle
			local springForce = -displacement * config.SpringStiffness
			local dampingForce = -state.currentVelocity * config.SpringDamping
			state.currentVelocity += springForce + dampingForce
		elseif state.currentAngle < config.MinAngle then
			local displacement = state.currentAngle - config.MinAngle
			local springForce = -displacement * config.SpringStiffness
			local dampingForce = -state.currentVelocity * config.SpringDamping
			state.currentVelocity += springForce + dampingForce
		else
			if not state.isDragging then
				state.currentVelocity *= config.Damping
			end
		end

		local isLatching = false
		if config.AutoClose and not state.isDragging then
			local angleToMin = state.currentAngle - config.MinAngle
			if angleToMin > 0 and angleToMin <= config.CloseThreshold and state.currentVelocity <= VelocityTolerance then
				state.currentVelocity = 0
				state.currentAngle = lerp(state.currentAngle, config.MinAngle, LatchSpeed)
				isLatching = true
			end
		end

		if not isLatching then
			state.currentAngle += state.currentVelocity
		end

		local previousState = state.state
		if isLatching or (state.currentAngle <= config.MinAngle + AngleTolerance and absVelocity < VelocityTolerance) then
			state.state = "CLOSED"
		elseif state.currentAngle >= config.MaxAngle - AngleTolerance and absVelocity < VelocityTolerance then
			state.state = "OPEN"
		else
			state.state = "TRAVELING"
		end

		if state.state ~= previousState then
			if state.state == "TRAVELING" and previousState == "CLOSED" then
				state.sounds.Open:Play()
			elseif state.state == "CLOSED" and previousState ~= "CLOSED" then
				state.sounds.Close:Play()
			end
		end

		local targetVolume = 0
		local targetPitch = 1
		if absVelocity > VelocityTolerance then
			targetVolume = math.clamp(absVelocity * 0.2, 0, 1)
			targetPitch = math.clamp(1 + absVelocity * 0.05, 0.8, 1.5)
		end
		state.sounds.Travel.Volume = lerp(state.sounds.Travel.Volume, targetVolume, 0.2)
		state.sounds.Travel.PlaybackSpeed = lerp(state.sounds.Travel.PlaybackSpeed, targetPitch, 0.2)

		local rotation = CFrame.Angles(0, math.rad(state.currentAngle), 0)
		door.CFrame = state.initialPivotCFrame * rotation * state.initialDoorOffset
	end
end

UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed or activeDoor then return end

	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		local target = mouse.Target
		if target and CollectionService:HasTag(target, DoorTag) then
			local door = target
			local state = doorStates[door]
			if state then
				activeDoor = door
				state.isDragging = true

				previousMouseBehavior = UserInputService.MouseBehavior
				UserInputService.MouseBehavior = Enum.MouseBehavior.Default

				lastMousePosition = UserInputService:GetMouseLocation()
				player:SetAttribute("InteractionState", "DoorDrag")
			end
		end
	end
end)

UserInputService.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 and activeDoor then
		endInteraction()
	end
end)

local function onCharacterAdded(character)
	character:WaitForChild("Humanoid").Died:Connect(endInteraction)
end

if player.Character then
	onCharacterAdded(player.Character)
end
player.CharacterAdded:Connect(onCharacterAdded)

for _, door in ipairs(CollectionService:GetTagged(DoorTag)) do
	task.spawn(setupDoor, door)
end
CollectionService:GetInstanceAddedSignal(DoorTag):Connect(setupDoor)
CollectionService:GetInstanceRemovedSignal(DoorTag):Connect(onDoorRemoved)

RunService.RenderStepped:Connect(onRenderStep)
24 Likes

math.lerp() exists. just letting you know that you dont need a lerp function

1 Like

Faster as well,if i remember correctly the math library in luau is calculated in C++

1 Like

Some feedback on your door interaction script:

⸻

  1. Using GetMouse()
    You’re mixing player:GetMouse() with UserInputService + GetMouseLocation().
    GetMouse() is deprecated and doesn’t play well with non-mouse devices. I’d stick to UserInputService methods only — cleaner and more future-proof.

⸻

  1. Click detection only works if the clicked part is tagged
    Right now, only the exact part with the “InteractiveDoor” tag will respond.
    If the door has multiple parts, most won’t work. Consider either:
    • Tagging the entire model instead of individual parts.
    • Or checking ancestors with FindFirstAncestor() until you find a tagged instance.

⸻

  1. Humanoid.Died connections can pile up
    Every respawn creates a new connection to Humanoid.Died without disconnecting the old one.
    This will cause multiple endInteraction() calls over time. Store the connection and clean it up on respawn.

⸻

  1. Looping through doors every frame with pairs
    onRenderStep runs every frame. pairs() allocates a new iterator each time.
    If you have lots of doors, performance will be better if you store them in a simple array and loop with a numeric for loop.

⸻

  1. All sounds are pre-created and Travel is always playing
    Every door creates 3 sounds and loops the Travel one at volume 0 forever.
    This is fine for a few doors, but wasteful if there are many. Consider:
    • Creating the travel sound only when dragging starts.
    • Destroying it when dragging stops.

⸻

  1. AngleTolerance and VelocityTolerance are hardcoded
    These values aren’t part of DefaultConfig, so you can’t tweak them per-door via attributes.
    It would be better to move them into DefaultConfig so each door can override them.

⸻

  1. Auto-close latching can look snappy
    LatchSpeed in lerp isn’t adjusted for deltaTime, so higher framerates will make it close faster.
    Making this framerate-independent would give smoother results.

⸻

  1. WaitForChild for static parts
    You’re calling WaitForChild(“Pivot”, 5) for parts that are already built in Studio.
    If they’re static, use FindFirstChild() with a warning instead — avoids unnecessary yielding.
2 Likes

Hey, i just got back from eating out but i really do appreciate the feedback. This was made in around a day for a game i was making as shown via the second showcase video, but I’ll be taking these into account and publishing a newer polished version when i have the time. Much love - 8

2 Likes