13 November 2024 - The Entity System, Part 2: Physics
<<< Previous Post
Next Post >>>
In the last post I went over what I wanted from an entity system. One of these points was physics rigs.
Well, I had a system already. The issue I realized pretty quickly is that I would be wrestling with Godot trying to make articulated physics rigs work (or, in English, character models that use physics to move, but can still be animated). It just wasn't worth the trouble.
The Problem
The issue comes from Godot's built in type for this: PhysicalBoneSimulator3D
. This is a system that does bone physics simulations for you. It's awesome, but it's meant to be completely autonomous. Think ragdolls. Animation is completely overridden (ignored), and bones simulate purely using physics.
I spent the better part of the last couple days brainstorming how to make it animatable while taking a bit of a break. I spent previous days making a system to try to retrofit control into this system and make all sorts of fancy maths to push bones to their animation targets and blah blah blah... Then my Eureka! moment hit: If I need to control the physics, then control the physics! Don't use PhysicalBoneSimulator3D
- it was designed to take control, not give it.
The Solution
So as you may know, Godot has a special physics object type called CharacterBody3D
.
In essence, it's a kinematic object1 with special utility methods designed to handle collision from both itself moving into other things, and things moving into it.
Now, it was designed to be used - as the name implies - as the collider for your entire character model (like your hitbox). But...
...There's nothing that says I can't assign a CharacterBody3D
to individual bones to simulate them. I would have to simulate them manually, yes, but that's precisely what I need! It's a bit of a cursed use but at the same time it's a perfectly valid and intentional use. Very strange solution indeed.
I'm mostly writing about this because I am quite excited to have found this solution after a couple days of banging my head against a wall in confusion. I'll keep you all posted on how it's going.
-
A kinematic object is a physics object which cannot be moved by pushing it; applying a force to it does nothing. Instead, it is designed to be moved manually. ↩