Home Contests & Challenges Archives Team Fortress 2

Jiggleboned Flying Pets Tutorial

qFcwObx.jpg
mirrors:
http://steamcommunity.com/sharedfiles/filedetails/?id=196054460
http://facepunch.com/showthread.php?t=1326101&p=42899662

If you sent things in to the Team Fortress 2 Workshop, you may already know custom animations will disqualify your item from earning the Gold Start Certification. I have sent in 2 items that uses jigglebones instead to imitation an animated item. At the time of submitting the relevant workshop items, I seem to be the only person who have used the jigglebone system in this fashion. Maybe nobody invented it before me. Maybe nobody simply could be arsed to even waste their time trying. Whatever the case, due to its rarity, some people have asked me to explain how this is done. I always said I would do it if one of the items using this mechanism is accepted into the game. That has come to pass, so I am writing this guide now. I'm just going to write as I go, so it may be longer than necessary. I'd rather you skip some parts than someone else needing info and not finding it.

I have told some of those same people that I used a fairly involved system of mathematics to imitate flight animation exclusively through jigglebones. Luckily for you, that is no longer true. I have since discovered a drastically simpler method, which employs only the fundamental basics of physics, while at the same time also having less disadvantages. This new method is used on both Quoth and Guano, the two aforementioned items that were accepted into Team Fortress 2, so you can decompile their in-game files if you wish to study a few examples. Here's a jigglebone decompiler http://downloads.obsidianconflict.net/jigglebone-decompile.exe if you wish to use it. This guide will explain how to use this method. You will need to already be familiar regarding working with models and jigglebones for the gold star importer. I am by no means an expert modeler, so if you use Blender you can probably follow along and maybe even find shortcuts I miss. For any other modeling program, I have no clue how they even work and you are on your own.

You will also need to understand basic algebra, specifically plugging in numbers into equations and the concept of absolute values.

There are multiple components to this method. Each one increases the lifelikeness of the motion. I will walk through creating them one component at a time, by building a simple sample bird and adding those components one at a time. Each will involve going back and forth between your modeling program and the gold star importer.

As you may already know, jigglebones are basically pendulums. Like pendulums and unlike animations, they cannot move under their own power. They only move when something disturbs them and moves them away from their resting state. In case of a jigglebone, something needs to move it across 3d space. As an item attached to the player character model, the movement of the bird jigglebones would originate from the player character model itself. When the user moves the mouse or uses the wasd keys, the character model moves in the game world, and that movement propels the jigglebones.

Of course, an actively moving player would give plenty of movement for the jigglebones to work with so that situation is not a problem. An AFK player is a different issue and needs to be addressed.

In addition to user input, the character animation alone also moves the jigglebones, so even when the character is left alone idling, the jigglebones can still receive movement input through the idle animation. The idle animation would usually have very minor movements compared to the user actually moving the character. As a result the jigglebones may not move as significantly if the character is simply idle for all past, present, and future times. there is a way to alleviate this, it will be in part of this guide later.

In the case of Team Fortress 2, the idle animation involves standing upright and breathing while holding the weapon that spawns with the character. This animation will be the ONLY thing that can propel your jigglebones if a player is AFK. Therefore your item must be tailored to this animation, lest it breaks the illusion that your bird is flying under its own wing power. Keep this in mind.

Create your flying pet. I prefer starting with the pyro because of the airblast ability. In the itemtest map it will allow you to test the item on yourself as well as imitate someone else moving by airblasting them.
Let the wings spread open horizontally.

01
yWm4p2i.jpg

02
sr08SiI.jpg

Extrude a bone called bird_body from bip_head. Disconnect them but keep parenting. Extrude a bone called bird_wings from bird_body. Disconnect them but keep parenting.

03
eiHqizK.jpg

04
SuTxjMB.jpg
Position bird_body at the assumed center of mass for your bird (or whatever you are making) so that it would rotate in a natural fashion if placed in a freefall. Imagine where the shoulders of your bird would be, then position bird_wings between the bird's shoulders. The positioning for bird_wings is probably not necessary, but will help you stay organized.

05
sOnjDAS.jpg

06
yyrerGM.jpg

07
CABp1kA.jpg

Now to assign bone weights. Normally you would just place the bone at the joint, make the bone flexible in the QC, and then just assign the vertices of a rotating object with the full weight of 1. We can't do that here, because we are not using the rotation of the jigglebones here, because:

08
ANPhBbf.jpg

We will be using the base springs instead, which provides translational movement instead of rotation. The bone itself will entirely bounce up and down vertically and each vertex will follow it, translating up and down in unison, to such an extent that the wing will LOOK LIKE it rotates from the shoulder as one coherent piece of physical object. This will be accomplished by the bone weights.

A drawback of this method is that the wings will not reach out further horizontally in the middle of its travel like a real wing would. Instead, the horizontal length will remain constant while the true length of the wing will change.

09
IHUf4t5.jpg

We can keep this flaw hidden with help from 2 facts. 1: the wings are going to be moving constantly, which means their actual lengths in any single instance in time, and by extension a comparison of their actual lengths between two instances in time, would be difficult. 2: the length difference minimizes with the angle, so as long as the wings are not forced to flap extremely high or low, the flaw can be kept to a minimum.

You can tell this optical illusion works because you didn't notice this flaw in the game before reading this guide.

Back to figuring out the bone weights of each wing vertex. They are going to be determined based on a linear distance from the shoulder along an axis. If your modeling program has no automatic methods to do this, we will calculate them here. Identify the axis that is parallel to the wingspan. In the case of this model, it is the x axis, so this guide will refer to coordinates and numbers in the x axis.

10
JKt67Ag.jpg

Locate a vertex at the base of a wing that is as close to the shoulder as possible. This will be the base of your wing. Note its x coordinate.

11
0oYbkxx.jpg

Locate the furthest vertex of the wing. This will be the wing tip. Note its x coordinate.

12
FcNjN9Z.jpg

All vertices on the body side of the wing base vertex can just be fully assigned to the bird_body bone. Nothing special here.

13
EZHpoSn.jpg

Refer to picture 14 below for bone weight formulas, along with an example vertex.

14
exZYIWX.jpg

You can double check your math to an extent. the sum of bone weights for any single vertex should be exactly 1. In Blender, if your math is correct, clicking the "normalize" button under your bone weights display should change exactly nothing. If the bone weights changed you did something wrong with that vertex.

If your item has detailed objects on the wings that involve many vertices, you may be able to save time and just use the same bone weights for them all, but you should check to make sure the wing top surfaces don't clip under the wing bottom surfaces during movements and vice versa. You'll have to check this in the game.

Import your model into Team Fortress 2. We are not submitting it immediately, so give it a simple name. This way you can just type the same name next time and the importer will automatically load your progress. Yes, it does that, in case you didn't know.

Use the following jigglebone codes in the QC for bird_body. These are from Quoth. They may not work perfectly with your item but is a good place to start.

15
isv8CLs.jpg

Replies

  • heinous
    Options
    Offline / Send Message
    Just a brief summary of these codes if you didn't already know. Is_rigid tells the game engine to let the bone freely dangle at its base. The large length and tip_mass values will cause the bone to obey gravity to a high extent. This is how Robro, Balloonicorn, and other flying companions stay upright. Nothing special. Has_base_spring again gives the bone the ability to translate along each axis. Stiffness and damping determine how closely and quickly the bone reacts to movement. The constraints dictate the maximum distance the engine should allow the bone to lag behind before overriding the spring settings and just forcing the bone to stay within that distance. Nothing special here either.
    now onto bird_wings:

    16
    yauSSLU.jpg
    We are completely forbidding it from any rotation, so the angle constraints are set to -0 and 0 to give it no range of movement. The rest of the flexible portion of codes is just arbitrary, set to some conventional numbers to avoid glitches. The has_base_spring here is what allows the wings to flap. Damping is set to 0 for constant movement. Base_mass and stiffness determine the flapping magnitude and frequency, so adjust to your liking, keeping in mind the spring should not be so weak that it cannot rebound during a full speed run, in which case it would be stuck at the maximum point of travel allowed by the constraints and stay there until the player changes direction or stops. Or maybe you actually want that, if you desire some kind of similar posture from your bird, such as gliding. That would be up to you.

    The constraint is one of the aforementioned means to hide the flaw of the variable wing length. As you can see, up_constraint does not necessarily correspond to vertical movement. It depends on how your bone is oriented when you exported the model. Just play around and you'll figure it out. Once you do, set the rest to the desired amount. For this model those ranges are -0,0 because I do not want the wings to move back and forth, nor side to side, only up and down.

    The actual up and down constraint, once you figured out which one it is, should be set low enough that the variation is not noticeable even at extreme movement by the player, but not so low that the spring constantly gets stuck at its limit. Trial and error would give you an idea of what values would work best with your specific model.

    Verify and finish, but don't publish. Open the itemtest map. By default your game has jigglebones enabled but automatically turns them off momentarily if your framerate dips below 45. We need to disable that cutoff. Go into console and enter "cl_jiggle_bone_framerate_cutoff 1" to disable jigglebone framerate cutoff. Use 1, not 0. 0 disables jigglebones entirely and then you won't be able to test your item. We want jigglebones enabled, but the cutoff disabled so that it does not interrupt our testing. If you want to always leave jigglebones on without needing to type that code every time you start the game, you can copy and paste that code into your autoexec.cfg

    Once that is done, equip your item. Wings should "flap." Don't worry if the flapping is minimal. This is expected when the idle animation is the only thing powering the jigglebones. Airblast the bot, the wings should flap a proper amount after that. This is only a temporary fix to see the motion just so you can make sure they are working. We will fix this really soon.

    17 gif
    b1j728A.gif
    If you experience the upside down model problem above, your bird_body is upside down while the model is upright. The game is spawning the model upright properly, while the bone is telling the game that it is wrong, so gravity takes effect and swings the model 180.

    Go back to the modeling program, focus on bird_body.

    18
    t3GMKZn.jpg

    Rotate bird_body along its own axis 180 degrees.

    19
    7EWf2j4.jpg

    In Blender it is Ctrl+R and if you keep the magnet on the rotation will snap to important values, one of which is 180. Unfortunately the rotation amount for this action will only show up as radians in the lower left window, so just make sure it's near pi (or 3.1416)

    Save, export, launch TF2, import, verify, finish, open the itemtest map and load the item again. Remember to use "cl_jiggle_bone_framerate_cutoff 1" again.

    20 gif
    rsk5KBM.gif

    The model is now upright. If it was upside down before, it will now be upright but wings flap minimally. This is because, when the model was upside down before the fix, the game would spawn it upright and immediately swing it upside down. The swinging motion was what propelled the wings. Now that the model spawns upright and stays that way, that swinging motion no longer exists, and so the idle animation is the only source of propulsion for the jigglebones, which only provides minimal propulsion. We are going to fix that now.

    Go back to the modeling program. Enter side view of your model. Rotate bird_body and bird_wings, together as one unit, slightly away from the horizontal. I suggest using the head of bird_body as the center of rotation. Repeat for the model itself, preferably sharing the same center of rotation. I personally prefer upward by 30 to 45 degrees.

    21
    kpUNmqI.jpg

    22
    2Bq2lW1.jpg

    There are some things to consider when choosing this angle. It should be enough that when the game's gravity swings it back toward the horizontal (like a pendulum), the force would be enough to propel the wings. However, in Team Fortress 2 you need to worry about its appearance in the loadout screen and 3D character HUD. Remember: loadout screen and 3D model HUD instances of your item will have jigglebones disabled. Your item's initial pose will be what is shown. If your chosen angle is too high it would not look natural. Lastly, you have to judge the appropriateness of this angle on the character idle animation, not reference pose, of EACH CLASS because the idle animation is what is shown on the loadout and 3D HUD models.

    Pick a good angle that looks good on the loadout screen while giving the jigglebones the momentum they need. Luckily you can upload different models for each class. I think I have 5 different models of Quoth for the 9 classes, and the only difference between them is the amount of tilt discussed here. I am not sure if Valve implemented them or just used a single copy for all 9 classes, but the fact remains that when submitting to the workshop, it can only help you if everything is as presentable as possible, which is why I want the wings to work during idle in the first place. make sure the bones are not upside down again.
    Save, export, launch TF2, import, verify, finish, open the itemtest map and load the item again. Remember to use "cl_jiggle_bone_framerate_cutoff 1" again. It should now be upright and flapping a decent amount on the bot even without you airblasting it to move it.

    23 gif
    uspdkPQ.gif

    This is the gist of the mechanism behind a perpetually flapping pair of wings. Everything below this is just more things to do to make the motion more pretty and lifelike.

    At this point, the wings appear to flap as a pair of solid rigid pieces. This may work for your item, for example if your item was an insect like a giant roach. However, birds have more complicated wings, so a more complicated imitation might breathe more life into your model's movements.

    At this point of "inventing" this method, I've brainstormed a few ways to improve it with some fellow modelers. Hell-met and Snookypookums have taught me much about bird flight, the latter of whom even provided a link that analyzes bird flight for the sake of animation, which I am providing here. Be warned, you will come to realize many games actually animate birds WRONG. I am talking about big name games here too, so be prepared that learning the things in that link may ruin some games for you :/

    http://www.brendanbody.co.uk/flight_tutorial/index.html

    Afterwards I have decided to spend some time watching birds fly in real life. In addition, Neodement has suggested I play with the bone weights some more, giving the wings a curvature that varies with the wings' positions relative to the horizontal plane. This seemed to be on the right track, but after messing around a little, I felt the calculations involved to figure out the correct bone weights would have been too complicated. This method was also lacking something I have personally observed from bird flights. The tip of the wings lag behind slightly in terms of time, probably because they are lighter weight with higher air resistance and less muscular strength than the rest of the wings. I could replicate a simple bend in the wings with bone weights, but it would require addition bones if I wanted portions of the wings to have even a slight lag. In fact, with additional bones, the bending of the wings can just be generated through them instead of using bone weights, so using more bones seemed to be the best solution. that is what we are going to do here now.

    For the purpose of this guide we can label a bird wing with 3 sections, analogous to the biceps, forearms, and fingers of human arms, portrayed below:

    24
    LLZHsT1.jpg

    Note that for our purpose, the portion involving the fingers will have to include the feather lengths, unlike in the diagram.

    Extrude a bird_wingmids bone from bird_wings. Then extrude a bird_wingtips bone form bird_wingmids. I just leave them connected. I never tried to disconnect them.

    25
    0xUNxP7.jpg

    Next, separate the wings into three sections, corresponding to the biceps, forearms, and fingers equivalents mentioned earlier. Here I made the sections roughly equal in length. In Blender you can use the knife tool. Make sure cutting through is enabled so the underside is cut too.

    26
    12Z47R5.jpg

    After that, you need to redistribute the bone weights of the wing vertices. The formula is the same, you just have 3 bases and 3 tips so you need to mind which ones the vertex you are working on should fall under. In the example below I have color coded every single vertex, labeling them with their bone weights in the respective colors of the bones. Obviously the body vertices are still weighted to bird_body.

    27
    I7xSNkf.jpg

    Save, export, launch TF2, import. Use the following codes in the QC for bird_wingmids. This is from Quoth. It may not suit your particular model, but may be a good place to start.

    28
    ZLEd8UH.jpg

    Likewise, below are the codes for bird_wingtips.

    29
    O11vY44.jpg

    Once again, there is nothing special about these codes. They are only used to make these additional sections lag behind bird_wings slightly. Experimenting with the values may help you find the best settings for your particular model.
  • heinous
    Options
    Offline / Send Message
    Verify, finish, enter itemtest map, disable the jigglebone automatic shutoff, load your item. The example below is problematic.

    30 gif
    H3CvI4P.gif

    The wing tips translate too far up and down. This totally breaks the illusion previously mentioned, and completely exposes the flaw that the wings vary in length over time. It would be wise to decrease their travel. by changing the forward constraints of both bird_wingmids and bird_wingtips from -5,2 to -2,1, their travel is lessened by not allowing them to deviate too much from their parental bones.

    31 gif
    VVZWzag.gif

    There is one more thing we can do to make the item more lifelike. You may have noticed from previous gif images, the entire item appears to hover in place, or at best move up and down in sync with the player character model's head, even covering the same distance. This is too rigid and mechanical, unbecoming of a living breathing bird. We can do something to improve that. create jiggle_base. Make it the child of bip_head. Make it the parent of bird_body. Put its tail on the head of bird_body and connect it. Put the head of jiggle_base somewhere far.

    32
    DYIHXaA.jpg
    The positioning of the jiggle_base head is nothing technical. Feel free to play around until you find a position that makes your model move convincingly.

    33
    4fMb7Gw.jpg

    Jiggle_base will be flexible. We are taking advantage of another illusion. An object rotating around a faraway point in space will have a minor arc in its travel and minimal change in heading, appearing as simply translation instead of rotation. With the head of jiggle_base being far enough away, the bird will appear to bob up and down with a negligible arc in its travel. In addition, the minor change in heading will be unnoticeable but give propulsion to the pendulum motion, in turn propelling the wings. It's not an exact science, but will at the very least give some variation to the movements to avoid appearing as a looping animation, if not outright give it more power to propel itself.

    Save, export, launch TF2, import. jiggle_base QC codes is just run of the mill flexible coding, nothing special:

    34
    0Fg1xZw.jpg

    Verify, finish, enter itemtest map, disable the jigglebone automatic shutoff, load your item. You are finished and as you can see the bird no longer strictly follows the player model.

    35 gif
    R3g4LzJ.gif

    I can go over the OLD method, but there's not much benefit that method can provide you, and the step by step guide for it will be even longer than this guide, involving even more advanced physics. In short, you need to find the frequency of the idle animation, then design your jigglebones and QC codes so that the pendulum action has matching natural frequency by calculating the necessary spring constants, masses, and lengths. These numbers can be deduced from the frequency by using Newtonian physics equations for springs, oscillations, waves, etc. You will need to know the gravitational constant of the game engine's universe (800 for TF2 according to Valve developer wiki).
    This will give you a jigglebone system that has the required natural frequency to resonate with the idle animation, resulting in an item with movement that not only is propelled by the animation, but also resonates with it to amplify itself over time, so that the motion actually becomes more exaggerated the longer the player is idle. This is going to require advanced placement high school physics knowledge, otherwise known as college level physics if your school does not provide such a curriculum.

    Now you can go out there and make your own flying pet Workshop submission, instead of doing the whole sour grapes routine and calling them fucking stupid.
  • Baddcog
    Options
    Offline / Send Message
    Baddcog polycounter lvl 9
    Yikes, math, lol.

    Nice tutorial. I had no idea you put so much thought into them :D
  • heinous
    Options
    Offline / Send Message
    Baddcog wrote: »
    Yikes, math, lol.

    Nice tutorial. I had no idea you put so much thought into them :D

    and i don't want to ever again! :nerd:
  • circle of friends
    Options
    Offline / Send Message
    circle of friends polycounter lvl 10
    Amazing writeup great stuff
  • EmAr
    Options
    Offline / Send Message
    EmAr polycounter lvl 18
    Thanks a lot for the tutorial! So, that's why my chicken can't fly :P
  • brandycarson
    Options
    Offline / Send Message
    I will enjoy with this one, will try to work on it. Thanks.
  • charkiewlson
    Options
    Offline / Send Message
    This tutorial will somehow guides me all through out my learning curves of this similar interest. Thanks
Sign In or Register to comment.