I am working on a VR project in Unity and wanted to learn more about Active Ragdoll physics. With this the idea is a character is always able to be affected by gravity and external forces. I found some cool people doing the same (MetalCore999, RedStoneBR and DavidKim). They all use something called configurable joints in unity to achieve this affect. Naturally I wanted to know more, and started looking around. The unity manual has some ok documentation, but not enough to do what we want. Even other pages have some decent additional information, but still not quite what I was looking for. So my purpose is to understand what the different settings do and to capture animations of these changes so I (and perhaps we), can better understand configurable joints as it pertains to active ragdoll.
To get started, we open up a new unity project. I added a plane and extended the scale by setting the values to (10,1,10). I then added a lighter red material to the plane. I added a sphere and added a rigid body and unclicked both use gravity. I kept the mass at 1 and set scale to (.5,.5,.5). This sphere will be our collider to help determine what is happening.
We then add a cube. I set the scale to (0.5,1,0.5) to better represent an arm. This will be our forearm. In the inspector, add a configurable joint to the cube. It should look like this. There is a lot here and easy to get overwhelmed. So let’s try and understand some more. If we press play game, our cube will fall straight to the ground.
This might be a good time to talk about axes. From the perspective of the cube looking at the camera. The Y axis is up (+) and down (-). The X axis is left (-) and right (+) and the Z axis if forward (+) and back (-). These are important to have a base understanding of. So if we look at our configurable joint, we see X,Y,Z motion and Angular X,Y,Z motion. Since our cube is falling down due to gravity, what happens if we adjust the Y motion from Free to Locked. As you can see below, it stops movement downwards, but if we hit it with a sphere it topples over. This is because it is allowed to rotate (on the Z in this case) and then the X axis gets affected by gravity and its falls down.
So let’s lock the Z angular motion. When you think about the angular movement, its best to think about where the axis is pointed and how the object can move around the axis. In this case, the Z axis is pointed forward, so movement around the Z is like a propeller. The Y axis angle would be like spinning like a top. The X axis is a little odd with this one, but imagine the top is the elbow. It would be like a bicep curl. So let’s try locking the Z angular motion.
Interesting right, so doing the same activity now means the block slides on the X axis. This would be quite weird for an arm to do. So in most cases, you are going to want to keep all X,Y,Z motions to locked. I will point out later when you won’t want to. I won’t show the same for pushing the cube from behind, but if we did, it would fall down similar to pushing it without the lock. However, to prevent rotating and falling down from behind, we would lock the X angular motion, and then pushing it from behind would make it slide forward.
Now let’s look at the Anchor. It should currently be set to (0, 0.5, 0). You can see a tiny little black and red axis at the top of our cube. In our case since this will be an elbow, its right. In most instances it defaults to one of the top, as far as I can tell because usually you want to do something near it. But what if we wanted that propeller. Let’s change it to (0,0,0). The black and red arrow should now be in the center of our forearm. And if we hit it starts spinning like a propeller.
What if we wanted it to move on its own. Well to do that we can mess with the Target Angular Velocity. If we set that the Z to 10 and press play, nothing happens. We can still hit it and it will spin, but not automatically. We need to look a little lower at the Angular YZ drive. The position spring and damper. These were a bit hard for me to understand, so let’s so a few attempts. If we keep the angular Z velocity to 10 and set the Angular YZ Drive damper to 1 with the Angular YZDrive spring to 0, the cube spins. Neat!
So now let’s mess with the spring. If we set that to 1, we can’t really notice anything. But if we do 7 we can see the propeller kind of wants to stop at the top, but gets pushed to go again. If we change it to 10 the propeller stops. Feel free to play around, but it seems that to stop the angular velocity, the spring must be Damper * velocity.
Now lets mess with the spring by itself. Reset the Target Angular Velocity to zero, and the Angular YZ Driver Damper to 0. Set the Angular YZ Drive position spring to 1. Hit play. We are going to messw ith the Target Rotation on Z. The difficult part to understand with these, are they are not angles, but quaternions. I still don’t fully understand Quaternions, but what I can tell you is that I had to use a calculator. To come up with the table on the left. So using 1 is a complete 90 degree turn, but 180 degrees is infinity.
So what we are going to do is show you the spring set to 1, 5, 10, 50, 100. This will be activated by changing the Target Rotation Z to 1 (90 degrees).
I think this gives us a good idea of how the springs work when we rotate and object. Now let’s try and make this forearm behave closer to a forearm.
To do that we need to mess with the angular limits. First go back and change the anchor back to where the elbow should be. So let’s think about your elbow. If that anchor is the pit of your elbow, you can curl up to close to your shoulder (X). But you can’t push it back (-X). Also you have limited side to side movement (Z Axis). And about a 180 degree twist (Y Axis) (palm down to palm up). Not so much your elbow as your arm. Let’s mess with the angles. Set the X and Y motion to limited, but the Z motion to locked.
So lets set the following
Low Angular X Limit to 0
High Angular X limit to 165.
Angular Y Limit to 90.
So if we did this right, we would expect we could make the block curl up towards the to be placed shoulder. We shouldn’t be able to move it like we previously did as a propeller, since elbows don’t do that. Last we should be able to rotate it 90 degrees left and right. (Note. We may need to edit this later, as I’m not exactly sure how this will work when on a rigged elbow)
IT DID IT! The first test shows the elbow curls up and when we let it go returns to the normal position. We can edit that from being a hard stop using the Angular X Limit Spring and Damper. I tested it and kind of liked 5 spring, 3 damper. The next test we did was hit from the z, which shouldn’t move. We get some resistance which spins the arm. Seems normal.
Please join me in my next iteration where I will connect this forearm to a shoulder and a body.