Advanced Collision Shapes
Games often use colliders that don’t match the object’s shape. Complex ones are costly to compute, and simpler shapes usually feel better to play with. Let's take a look at an example.
Intro
One of the most common examples is using a capsule for the player, which many 3rd and 1st person games do.
A simple capsule is easier to slide along the ground and walls, has a low computlation cost with respect to collisions, and won't get caught on corers the way a true-to-form skeletal collider might.
However the auto-generated methods from the pervious article, Physics Collisions, don't give you that level of control. This is where physics inheritance and the use of joints (more detail on joints here) come in.
Practical Example
Let's say we have a spikey ball that we want to roll through our physics simulation a-la Indiana Jones. None of our auto-generated options will do the trick. The box won't roll at all, the capsule will only roll on one axis, and the edits might roll but probably not as smoothly as we'd like (despite how it look - after all games aren't about realism, they're about feel)
Here's how we'd go about using joints and physics inheritance to get our spikey ball to roll whilst still looking exactly as menacing as we'd like.
Step 1: Parent Joint
First we'll nest the ball model inside of a joint.
- Navigate to the Stage Tab, this is where joints are created.
- Select the spikey ball model
- Click on the (+ joint) button
- An orange dot will be added to the scene (representation of the joint) and the model will become nested under the new joint
Step 2: Collider Model
Now we're going to add a new model as a sibling of our spikey ball. It's going to be a nice simple sphere. Its only job is going to be to define the shape we want the physics engine to see. Let's add that now.
- Navigate to the Sculpt Tab (where we create models)
- Click the (+ model) button
- Add a sphere to represent the "physics shape" we want this ball to have
- Rename the model to "collider" and drag it under the joint
Don't worry if the sphere is covering up your ball. We'll address that in a second.
Step 3: Physics
This is where we turn on physics and make use of unbound's inheritance system - which allows us to control how physics cascade down the tree and how each model participates (or doesn't)
- Return to the Stage Tab (or Play, both allow physics editing)
- Select the joint
- Select "Dynamic" from the physics dropdown
Note
We chose Dynamic because we want this object to be affected by gravity, falling and tumbling as it would in the real world. For more info on physcis object types, read this article
And of course, we'll want to set the collision type to edits as colliders because we want a spherical collision shape.
Step 4: Inheritance
Since we've set the parent joint to Dynamic, the next task is to decide which of its children contribute to the simulation and how. If we select the spikeyBall child then click on the physics dropdown, we'll see a number of options:
- inherit - adopt the parent's (in this case, the joint) physics type
- platform - behave like a platform (explicit)
- dynamic - behave like a dynamic object (explicit)
- stop - no physics at all
Let's determine how each child will contribute. We can do this by selecting each child individually and then making a selection from the dropdown shown above.
- Since the spikeyBall model is just for visuals, we'll set this one to STOP.
- The collider, on the other hand, should be set to INHERIT because it's going to copy whatever is set on the joint.
With the spikeyBall set to STOP and the collider set to INHERIT, when we run the physics simulation we can see it rolls nicely along a ramp without bumping on the spikey tips. (this is what we want!)
Step 5: Visibility
The only remainig issue is that our collider is covering up the lovely SDF sculpt we made. Luckily for us, models can particpate in collisions even if they're not visible. From the organizer, click the hide button next to the collider and run the simulation again.
Tada!
Final Thoughts
Why do it this way? Had we used the spikeyBall's edits as the collider we would have been saddled with a much more expensive set of colliders that we don't really need:
You could use the setup above for more realistic rolling, but sometimes predictable movement feels better and fits the game’s design or performance needs.
The example at the top used this technique to give a complex shape, like a humanoid, a simple capsule collider. With the joint + physics setup, you get more control over which parts of the model handle collisions.