Check out Half-Life Re-imagined competition results!
Check out Skewing textures in Hammer, our newest tutorial!
Say hello to Jongmeister, our newest member!


Site Stuff






Feeling Blue

What's your favourite shade of blue?














7 mins


10 mins


22 mins


23 mins


32 mins


35 mins


51 mins



A gaming and technology blog by TWHL admins Penguinboy and Ant. A music blog by TWHL users Ant and Hugh.

Perfect Timing with Doors

Page: [1] 2

Tutorials > Half-Life > Intermediate > Perfect Timing with Doors


By Instant Mix (More from this user)
28th December, 2011
distance , speed , doors , trains
star star star star star (5 votes)

Perfect Timing with Doors - Page 1

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.



avatar Daubster says: star star star star star 28th December 2011, 14:51 PM
I like how you've included a detailed example on how it all works, good stuff!
avatar DiscoStu says: 28th December 2011, 22:56 PM
Nice. Simple and to the point. Didn't learn anything new, though :P
avatar Tetsu0 says: 28th December 2011, 23:52 PM
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 :)
avatar Captain Terror says: star star star star star 29th December 2011, 02:45 AM
this is really well done, and way faster than trial and error trying to match up the door speeds! Great work sir!
avatar SpaG says: star star star star star 31st December 2011, 08:50 AM
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.
avatar Instant Mix says: 8th January 2012, 14:25 PM
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.
avatar Stojke says: star star star star star 22nd February 2012, 21:50 PM
Awesome! Really nice tutorial, 5 stars mate.
avatar ciba43 says: star star star star star 17th May 2013, 20:59 PM
Greatd tutorial :D
avatar BshiftCalhoun says: 26th May 2016, 23:24 PM
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)
avatar BshiftCalhoun says: 29th May 2016, 21:52 PM
nvm what i just said it has nothing to do with the tutorial my bad
You must be logged in to comment.