What are Jiggle Physics, and How Do I Set Them Up in Godot?

Here’s how you can add secondary animation movement dynamically to your characters in your Godot game! Jiggle Physics can be used for a wide variety of appendages such as hair and clothing as well.

Published on Wednesday, June 26, 2024
godotblenderartanimation3Drigginggdscriptaddons

I’m still working on getting images up on this guide, so stay tuned!

Summary

The goal of this article is to describe the theory behind jiggle physics in video games, and different ways to implement them in the Godot Engine.

  • We will discuss how jiggle physics work under the hood in game engines
  • We will discuss the various solutions for implementing jiggle physics in Godot (or Blender) along with the pros and cons
  • We will discuss how to bake jiggles directly into animations using Blender
  • We will discuss the use of softbody or rigidbody simulations in Godot directly, and its current limitations
  • We will discuss how to use the Jigglebone and Wigglebone addons in Godot to apply jiggle physics to bones on a character rig
  • We will discuss using a script to make setting up many jiggle bones more feasible

Prerequisites

  • Blender 4.0 or higher
  • Godot 4.2 or higher
  • An existing 3D model with a rig
  • Some basic knowledge of 3D modeling (I have a comprehensive 3D modeling guide, if it helps: /tutorials/complete-3d-character-guide)
  • Some basic knowledge on Godot’s interface and GDScript

Add-Ons

Blender

Godot

Intro

Have you ever been mesmerized by a video game character’s flowing hair, marvelous capes, or other parts? Nowadays, game developers incorporate a nice little thing called jiggle physics to add visual interest to their games. But if you do it right, it can raise more than just eyebrows. In all seriousness, though, jiggle physics are just a form of secondary animation, and the inclusion of them can liven up your game greatly, even outside of more… lewd reasons. Now, let’s take a look at how jiggle physics works, and some different solutions to implementing them in the Godot Engine!

How do Jiggle Physics Work, Typically?

As mentioned earlier, jiggle physics are just a form of secondary animation. Take a running animation for example. Whenever a character runs, there’s going to be a force that’s indirectly applied to these parts by the head, the torso, the arms and legs that forces the appendages to follow suit. As a result, it creates a buttery smooth motion that complements the core animation. While I’ll be using the term jiggle physics for mostly the lols in this guide, I think it’s much better to refer to them as secondary animation, as jiggle physics can be applied to even things such as hair.

At the core, jiggle physics uses a physics function called Verlet Integration. Verlet Integration is a physics function used to calculate the future position of an object based on its past position and an acceleration value. It’s often used for rope and string simulations. Let’s treat a jiggle appendage like a rope as an example here. If you were to take a simple rope with only two points, you can calculate the velocity of one point by subtracting its current position from its previous position. However, we also have to constrain the bottom point so the distance between the two points is always the same. Therefore, the constraint will force the point to move in a more circular fashion. Then all you need to do is apply this simulation to all the points on the rope and it would look pretty good!

Xn+1=2Xn-Xn-1 + ant2

Or simplified,

Xn+1=Xn+ vn

Or in code,

x += velocity * delta

Typically, gravity is the primary force affecting the simulation. However, you can influence the feel of the jiggle by tweaking the stiffness and damping values. Stiffness affects the reaction it has to the external forces, in which larger values cause it to snap more aggressively back into position. Damping, on the other hand, affects how quickly the appendage returns to the rest position, as well as how much it oscillates. A higher damping value causes the appendage to slowly move back into place after being displaced, like a feather falling.

Stiffness: velocity += acceleration stiffness Damping: velocity -= velocity damping * delta

All right, now that you know how jiggle physics work, how do we implement them in Godot? Well, there’s actually a couple different options, and I’ll explore each one. There’s three main solutions - animating the secondary animations directly before exporting to Godot, using physically accurate simulations such as softbodies, and using bones on a rig. Each of these three solutions come with pros and cons, which I’ll explain along the way.

Animating Jiggles Directly into Animations

The first option is actually really simple - animating the jiggle physics directly. In 3D modeling tools such as Blender, you can achieve this by using physics simulations and then baking the simulation to animation frames. This method is great if you need to save on performance in your game, or if you want the animations to remain consistent.

From what I can tell, games like Super Smash Bros. Ultimate use this method. Smash Bros doesn’t need to share animations between characters, so there’s a lot of freedom of expression for each character. More importantly though, Smash has very tight performance constraints, having to run at 60 FPS on the Nintendo Switch after all. Rather than adding processes to calculate the secondary movement in the game engine, baking the jiggles into the character animations saves a big deal of performance. In addition, having that level of consistency for a fighting game is great for readability too - if for some reason King K. Rool’s cape flowed over his face, who’s to say the opposing player would know what move is coming next?

The upside of this approach can also be a downside, however. Baking secondary animations into the character animation only really works well for that one character. Many games like to reuse rigs across characters, and who’s to say the other characters would have the same appendages in the same places? Another thing to consider as well is that some games would prefer the dynamism of the secondary animations to be a factor. If secondary bones respond to the varying movement of the character, it can appear more lifelike. Ultimately though, this is a preference and it’s up to you to decide if this matters enough.

If you decide to use this approach, there’s two main ways you can go about it. One way is to use the physics simulations, such as the cloth or rigid body simulations and then bake those into your animation, or you can rig your secondary bones and apply the physics to them. In the context of Blender, which is the 3D software I’m using, cloth and rigid body simulations are not straightforward to bake into an animation, and I don’t nearly have enough experience here to explain it well. Therefore, we will add bones to the character’s hair, clothing, and other appendages within the rig, and then use this wigglebone addon to animate it.

To download the Blender wigglebone addon, use the link in the description to go to the Blender forum website. The addon is just a single Python file, but it’ll install just like any other addon. In Blender, open Edit > Preferences > Addons, and then click the install button to install the addon. Make sure to enable it as well.

Assuming you have your 3D character rigged, you can then modify the rig to add the additional secondary animation bones. If you want to learn how to make the rig, I’ll refer you to my complete 3D character guide where I go into depth on it. In a nutshell though, you basically just add a few additional bones to your rig and weight paint like normal. If you’re using Rigify like me, I recommend you change the top bone of each chain to the basic.copy_chain type, so you can see them when you are animating later.

Also assuming you have an animation already, enter Pose mode and make sure your secondary bones are visible. Select all of them and select the Wiggle Armature button here on the side panel as well as the Wiggle Bone toggle on the Bone properties tab. Now when you play an animation, wiggles will be added. Tweak the parameters as you like, and don’t forget to reset the physics state when you place the playhead back at frame 0. Once the physics is to your liking, press the Bake Wiggle button here, and the wigglebones addon will create a new action with just the wiggle bone animations.

The wigglebone addon creates a new Action inside Blender, so we will have to copy the keyframes over to the original animation. Before pasting the keyframes into the base animation, make sure that there are blank keyframes for the bones you added the wiggle to. Otherwise you’ll get something really janky. Another thing to note - the wigglebone addon creates a separate NLA section that blends the two animations, so make sure to remove the temporary action here as well. When you export your character animation, you should now see that the wiggles are baked into the animation! You may need to manually tweak the animation, but this is the basic gist of this method.

Softbody or Rigidbody Simulations

For more realistic and dynamic simulations, the second option is to set up softbodies or rigidbodies in Godot directly. At the time of publishing this video, I don’t recommend using this method, as Godot’s support here is not as straightforward.

The SoftBody node has a few problems. First, to use a part of your character model as a softbody, you’d have to do a workaround where you create the SoftBody node, copy the mesh into the SoftBody node and then hide the original mesh. The other, more prominent problem is that to make pins on your soft body, you’d have to painstakingly pick every single vertex on the mesh to pin.

Regarding the Physical Bones, it’s more designed for ragdoll physics than it is for jiggle physics. When you create the physical skeleton in Godot, it doesn’t work right if you remove certain bones, like the root bone, and it’s not straightforward as to how to clean it up. In addition, the different types of joints available are not very well documented, so I cannot begin to tell you how to use the six-degree-of-freedom joint in such a way that it behaves like a jiggle bone.

The good news is this method is overkill most of the time anyway. Given Godot is open source, I can trust that this will be improved upon over time to become a more viable solution.

Using Rigged Bones for Jiggle Physics

In my opinion, the most effective way to get dynamic simulations in Godot directly is to use jiggle bones. With the secondary bones on the rig, we would let Godot handle the physics with the Jigglebone or Wigglebone addons instead of baking them directly. While these are addons and not official code, they work more than well enough for our purposes.

The two addons are not identical, though. The Wigglebone addon offers more flexibility in general, allowing you to apply constant forces or base the motion on dislocation or rotation. It also has a nicer setup, and since it derives from BoneAttachment3D, you can select the desired bone from the dropdown. On the contrary, the Jigglebone addon derives from Node3D and you have to manually type the bone name for it to work. However, from my testing the Jigglebone addon is much more performant and it’s the option I’ll be using in this tutorial. I recommend using Jigglebone when you have many bones to animate, and Wigglebone otherwise.

To start configuring your jiggle bones, download the plugin of choice directly from the Asset Library within Godot, or from the GitHub repositories, which I’ll link in the description. Once downloaded, make sure the addon is enabled in your Project Settings. Go to Project > Project Settings > Addons and check the box next to it to enable it.

Next, open your character scene with the rig. To add a Jigglebone, click on the Add Node button or use CTRL+A. The Jigglebone or Wigglebone node should be available in the list now, so select it to add the node to the scene tree. Make sure to add the node as a child of the Skeleton node. For the Jigglebone addon, you’ll need to type in the name of the bone you want to modify manually, as it does not have support for the dropdown. It’s tedious, but you can always reference your Blender scene or the Skeleton in Godot to find the right name.

Now, you can configure the settings for the bone. Typically hair and clothing will have more damping as they tend to flow back more slowly, and breasts have more stiffness so they snap back into place faster. Feel free to adjust these settings to your liking, though. Afterwards, select the forward axis so that the crosshair points toward the way the bone would normally be facing. For example, the hair and skirt here would point downwards whereas the breasts point forward. Feel free to test the gravity setting as well, but I actually don’t use it for my rig because I found that the results look better without it.

To test the jiggle, move the crosshair in the editor to test the interaction. Once you have the settings the way you like them, you can then duplicate the node and set the bone names for as many bones as you want to configure. A quick tip - you can actually adjust the settings for multiple bones at a time if you have them highlighted in your scene tree.

The last thing to configure here is collisions for the Jigglebones. To be honest, I still haven’t gotten a great result with this, but you technically can set them up with the Jigglebone addon. The Jigglebone addon actually uses a CollisionShape to calculate collisions manually, rather than using any sort of built-in Godot physics. As of right now, it only works for Sphere shapes, but it’s enough to serve the purpose. With Godot’s BoneAttachment3D node, we can center the collision shapes around parts of the character such as the torso or hips, and it’ll work regardless of the position of the torso or hips.

To configure this, add a new node like before and search for the BoneAttachment3D node. Select a bone like the middle spine bone where you could have your sphere placed. Next, add a CollisionShape3D node underneath the BoneAttachment3D node and change it to the Sphere type. Make sure to disable it as well, so it doesn’t influence any other collisions with your character. The Jigglebone addon will still use it even if it’s disabled. Then all you need to do is assign this CollisionShape3D node to your jiggle bones and it’ll now use it during the simulation. You may need to increase the radius of the sphere to get it to work properly, well past what you would expect. If you need to add more collision shapes, make sure to make each Sphere shape unique so you don’t accidentally modify the radii of all of them.

If you’re having some issues getting the look you want, there’s a few things you can try. First, you can exclude the topmost bone in the chain. Sometimes it pulls too much and the result looks better without having a Jigglebone on the top bone. Also, if the physics gets screwed up, you can use File > Reload Saved Scene to reset the position.

The last thing to mention regarding the Jigglebone addon is that there is a fork of the addon that removes the ability to test the jiggle in the editor. This has two main benefits - when you save your scene it won’t change the position of the crosshairs every time, and it’s a bit cleaner and a bit more performant too. I prefer having the ability to test in the editor, but this may be worth using in the finishing stages of your game. The link’s in the description.

For hair Stiffness - 0.1 (so it flows back more slowly and doesn’t snap) Damping - 4 (so it still sways back and forth but doesn’t oscillate forever) For clothing Stiffness = 0.1 Damping = 5 (slower swaying than the hair) For breasts Stiffness = 1.5 (so it snaps back faster) Damping = 0 (making the movement oscillate more)

If You Don’t Like Having Many Jigglebones in Your Scene Tree…

Before we wrap up this video, I want to show you one more trick you can use, if you don’t like having so many jiggle bones in your scene tree. Instead, you can write a script that will initiate the Jigglebones for you when the scene loads. We’ll just make the script configurable enough such that you can specify the stiffness, damping and axis values for each type of bone.

To get started, create a new script and attach it to the Skeleton3D node. We’ll place it here so we have easier access to the bones inside the script.

As far as the code goes, we will first grab a reference to the Jigglebone node script so we can instantiate it later.

Then, in the _ready function, we will iterate through each bone in the skeleton and add the jiggle bones where necessary. The base of the code looks like this, where we will create a new jigglebone scene (rather than instantiate because it’s a script) and assign a name and bone to it.

However, this isn’t very useful as is. We don’t want to apply jigglebones to every bone in the body. Therefore, we can set up a Resource type to let us configure the jigglebones just the way we like.

Create a new script file in your project, and call it jigglebone_config. Start by giving it a class_name so we can refer to it in our skeleton script. Then, extend it as a resource and then add a few export variables to it. We’ll add name_pattern, so we can lookup bones that include the value here, the stiffness, the damping and the forward_axis. However, we would need to copy the Axis enum from the jigglebone script to use it here. No need to do anything fancy here - since it’s an enum, it just maps to numerical values anyway so it’ll work just fine.

Now, open the skeleton script again and modify it like this. We’ll first add an export var which will be an array of JiggleboneConfigs. This way, we can tweak the settings within the editor. Next, we will add an additional loop underneath the first one to iterate through the jigglebone config. All we need to do now is test to make sure the bone_name we’re on contains the pattern we’re looking for, such as “breast” or “hair”, and then we can use those config settings.

Finally, back in your character scene, you can now use the editor to add configurations. On the Skeleton3D node, you should now see a place to put your configurations, which is an Array. Add a new element, and then click the dropdown to add a new JiggleboneConfig. Type in a name pattern and the desired settings for each. If you test your scene now, you should see the bones were added and configured properly.

Closing Thoughts

That wraps things up for this video. Feel free to ask any questions you have in the comments, and I’ll do my best to respond. Remember, if you need more information on setting up your 3D character, check out my complete character creation guide. Thanks for watching, and have a fantastic day!

Sources and Further Research