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:
-
Place the Script: Put the LocalScript provided below into StarterPlayer > StarterPlayerScripts.
-
Create the BindableEvent. In ReplicatedStorage Create a BindableEvent with the name InteractionStateChanged
-
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)