Tutorial: Perfect Timing with Doors Last edited 1 year ago2022-09-01 11:55:47 UTC

Doors. Who doesn't love them? They can come in all shapes and sizes : standard rotating , sliding , even hexagonal doors! But have you ever had that time where your doors just don't cooperate? One closing before the other? One being completely out of sync? Well , here is a relatively simple way to fix that.

The Problem

The problem is caused by two ( or more ) doors of different lengths moving at different speeds.Because they are different lengths , the shorter / faster door will close before the other and leave an OCD-inducing time gap.

To fix this problem , we need to use some maths to find the speeds at which doors will shut at the same time.

The Solution

The root of the solution to this problem is the incredibly simple equation :
D = S*T
If you haven't seen this before , this is known as the DST formula ( Distance , Speed , Time ).
It allows you to figure out the duration , speed and distance an object moves or takes to move if you know the other 2 variables.

We will be using this derivative equation in this tutorial to do our work:
S = (D-LIP)/T
You can also use this equation to find out the time a door will take to open in case some variables are unknown to you.
T = (D-LIP)/S

The Method

For each func_door:
Find the length of your door in the direction it is moving , and the Lip value you have put in , if there is any.

Decide on a duration for the door - 5 seconds , 1 second , maybe even half of a second
S = (D-LIP)/T
For each func_door, divide the found length minus the door's lip by your chosen time. Set the func_door's speeds to these value, and both doors should shut at the same time.


In this example I've created an "odd door" , that being that the whole door compromises of two separate doors with different lengths.
Sweet and simple.Sweet and simple.
The geometry is as shown:
The dominant door (blue) and recessive (red) as shown.The dominant door (blue) and recessive (red) as shown.
Now as the lengths of the top section and bottom section are different , when both doors open , the bottom door will close before the top door closes. Unless you have a complex entity setup with the doors set to toggle , they won't open and close at the same time ( or arrive at the same time , for that matter ).
This is shown at the bottom right corner of the Hammer editor ; it displays the dimensions of the selected object.This is shown at the bottom right corner of the Hammer editor ; it displays the dimensions of the selected object.
From the editor , we can see that our first door is 96 units high. To complicate this further , we have set the lip of this door to 16.
The bottom door is 48 units high , with no lip.
NOTE : It isn't always the height used , It's only because this doors moves vertically. The distance measured is relative to the direction.

We want our chunky door to take a nice 2 seconds to open up, so here we input these values into our two equations
D = 96
LIP = 16
T = 2
S = (D-LIP)/T
S = (96-16)/2
S = 80/2
S = 40
D = 48
LIP = 0
T = 2
S = (D-LIP)/T
S = 48/2
S = 24
When I plug in 40 as the speed of the blue door, and 24 as the speed of the red door, the two will now open and shut at the exact same time. Piece of cake!


Commented 12 years ago2011-12-28 22:51:14 UTC Comment #100979
I like how you've included a detailed example on how it all works, good stuff!
Commented 12 years ago2011-12-29 06:56:40 UTC Comment #100980
Nice. Simple and to the point. Didn't learn anything new, though :P
Commented 12 years ago2011-12-29 07:52:03 UTC Comment #100981
Horray for math!
Nice Tut - Simple, easy to follow.
I used to not care about door timings, but now that i dont have to think for myself, i'm gonna apply it :)
Commented 12 years ago2011-12-29 10:45:43 UTC Comment #100982
this is really well done, and way faster than trial and error trying to match up the door speeds! Great work sir!
Commented 12 years ago2011-12-31 16:50:27 UTC Comment #100983
Now the only problem that remains, is calculating door height relative to the direction it will move, when doors move on a plane, or two axis (say, diagonally). Add more complex door shapes and you're better off guessing the timing :-D
Anyway, god work.
Commented 12 years ago2012-01-08 22:25:41 UTC Comment #100984
I was going to add that in Spag but then I thought nobody would need it. Now that you've brought it up , I might just.
Commented 12 years ago2012-02-23 05:50:15 UTC Comment #100985
Awesome! Really nice tutorial, 5 stars mate.
Commented 10 years ago2013-05-18 03:59:19 UTC Comment #100986
Greatd tutorial :D
Commented 7 years ago2016-05-27 06:24:31 UTC Comment #100987
a more simplier way is putting a trigger_multiple next to the doors and make them big enough so the player doesnt reach the doors before it start opening (thats if you dont want to block on the doors when youre running)
Commented 7 years ago2016-05-30 04:52:39 UTC Comment #100988
nvm what i just said it has nothing to do with the tutorial my bad

You must log in to post a comment. You can login or register a new account.