Unity3d has a few tutorials out there but one of my favorites is this official 2013 tutorial which is where the above gif is from. While the exact steps are a little different than what I’ve written below the base is still the same. To recreate the door we’d simply re-use the concepts below but just add a breakable force level to the joints.
Joints are great for breakable panels to rope physics, to bosses that can swing wrecking balls of death, to just Ragdolls.
The simple 101 examples of joint usage we’ll be doing are hanging platforms with interactable chains.
Simulating Chain Physics
Not always the most useful application but setting up swinging platforms from a chain teaches all the basics of “joint” physics so it’s perfect for this article.
For this example, I’m using 3D models with 2D Physics chains as it’s a bit easier to demo and explain. It works similar to 3D but you have a few extra settings.
First, we set up our base distance and point, this is a 2D distance joint to simulate a weight hanging from something in the ceiling. But we could also simulate a monster pinned to a chain attached to a stake or to the wall with the same setup.
This is as easy as just saying what two objects we want to utilize. For the top point in my example we don’t want the ceiling to ever fall so we need to freeze its x/y and remove gravity, this gets our box hanging as if on a rope.
We “could” stop here and just say it’s magically hanging, but players require those visuals to believe it’s working as intended.
Adding The Visual Chains
As in my first article on physics, the biggest thing to realize is a lot of physics simulation is “good-enough” work. We don’t require a simulated joint on every single length of chain, we just need enough joints so a player can suspend disbelief.
The way we connect each chain is by attaching a RigidBody to make it a physics object, then a Hinge Joint. From here we grab the “next” chain’s Rigidbody as our hinge joint’s focus to essentially say “you are connected to this object”, then we move the “Anchor Point” to where we want to simulate the hinge.
We repeat how many chains and joints we need, ending on the last object of our platform. And we apply an extra hinge to the top as well.
This creates believable enough hanging platforms.
Where to go from here
To stimulate more things, we could apply code or settings so when enough force or “weight” is applied it breaks the chain. Maybe we have a puzzle where enough physics objects need to get put on the platform to “break” it so it falls down revealing the exit.
What more if we didn’t need the platform so “rigid” to be used as a platform we could remove the Distance Joint and just trust the chain joints.
There’s so much you can do it just takes time to work it out, it all works off these base concepts.