The Physics of Doors

Published July 31, 2006
Advertisement
As any physics programmer worth his salt will tell you, one of the keys to fast and stable physics simulation is auto-disable. You want to auto-disable everything you can. Aside from mass-destruction sequences, most of the time, there are actually very few physical bodies in motion - and so it's worth taking the time to determine all the bodies you can leave disabled, and only wake them up when either they start moving, something constrained to them starts moving, or something in motion hits them.

A while ago I added some debug rendering to my engine that shows me all the physics bodies in the scene, and colours them based on their state: blue represent totally static bodies (scenery), green represent bodies in motion (being solved that frame), and red representing bodies that are currently sleeping (auto-disabled). A quick look at the bodies representing my doors showed them green all the time - meaning that the physics solver is recalculating them every frame even though they're just sitting there (because there's no animation playing).

While my first thought was that I could just leave them asleep all the time given they didn't actually need any simulation, I soon realised it's important to make sure they're made active when they're moving, or any auto-disabled bodies that are touching them won't react when they start moving (imagine a character hanging in the air when a trap door drops open beneath him - not good).

The first thing I had to do was let the physics engine know that these doors don't need any motion simulation - they're pure animation (i.e. no gravity, friction, momentum, etc). My physics engine allows you to lock specific axes on any given body (so for example on a see-saw, you want to lock translation in x y and z so it doesn't slide anywhere, then lock rotation around y and z, leaving it free to pivot around the x axis) - so for any animated scenery (like a door, or a lift) I just lock all the axes. The physics engine now knows this body is only there to interact with other bodies - it doesn't actually need any simulation itself.

Next, I just added some auto-disable code to wake the body up when it receives any motion from a controller (e.g. the animation) and put it to sleep whenever there's no motion present.

Here's the result - the first shot shows a door sitting full closed (notice that it's red, so it's not taking up any cycles), and the second shows it automagically waking up to open (in green). I can't tell you how many times this coloured physics feedback has saved me hours debugging stuff!

Disabled

Enabled
Previous Entry Sliding Doors
Next Entry Proximity Triggers
0 likes 4 comments

Comments

Ravuya
Neat console font.
July 31, 2006 09:52 PM
Milkshake
Funnily enough, that's actually not the font I wanted - on Windows I get a funky comic speech bubble style font. The one you see here is the OSX default "the font you asked for wasn't found" font. I've left it there because for development, it lets me see more characters per line =)
July 31, 2006 10:02 PM
Ravuya
Oh, I didn't know the game ran on OS X too. I am even more enraptured by your excellent cow avatar and Head Over Heels interpretation now, and wish to subscribe to your newsletter.
August 01, 2006 09:48 AM
Milkshake
Hehehe - OSX indies of the world unite! Thanks for your kind words. Does GameDev support newsletters somehow? I must admit, I didn't really poke around the subscription control panel too much.
August 02, 2006 10:40 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

Moose Sighting

1342 views

Constraints

1511 views

Moose

1248 views

Melon Golf

1791 views

Toon

1311 views

Spaceships

1063 views

Rendering Pt2

1156 views

Hardware Shaders

1189 views
Advertisement