How we created our climber - Part 3

How we gave muscles to our Ragdoll

By Geert Beuneker

How we created our climber Part 3 thumbnail

So far we can move our arms and legs which is a good start, but we don’t have any way to actually use them to pull our body up on a mountain. To make this work we have tried a couple of approaches.

Just add force

At first we started simple. We have a rigidbody capsule for our climber’s torso, so all we need to do is add some force to it and it will move up. So the first setup was just: you press a directional key and that pushes the body in that direction. So for instance pressing W adds an upwards force to the rigidbody making it move up. However, as soon as you let go the body would fall back down. Our character’s hands and feet are anchored firmly on the mountainside so that prevents our character from falling back down. Great! Nice and simple.

Hold W for force

While this does work it was very annoying to control, because as soon as you let go of the movement buttons the character would completely relax and slump back down. This meant that you always had to keep pressing the W button while also aiming your limbs at the same time. And it would always push the character with the maximum force in your movement direction making for erratic movement patterns which looked very unnatural.

We wanted to allow more subtle, controlled movement so we had to find another way.

Core movement target

Our next idea was to use the movement keys to move an invisible target around and then move the center of our body (our core) towards that target as if it was attached to it with an elastic band. The further the core is from the movement target, the harder it will push towards that target. This meant that you had very fine control on how hard to push towards a certain direction and made sure that you didn’t have to keep holding down the movement buttons to climb upwards. This was certainly a step in the right direction!

There was one problem though. Our character always moved towards its target stomach first. Almost like it was attached to an invisible target with an elastic band… (I wonder why??) So this system needed some extra tweaking. Stomach First

Multiple movement targets

The next key insight was gained by looking at our arms and legs and specifically where they attach to our bodies: shoulders and hips! That is ultimately what is being moved when we use the muscles in our limbs. So that is also what we should be using to move our climber.

Instead of one movement target, we now have 4 movement targets which attach to our climber’s shoulders and hips. This caused our climber to stay nicely upright and still move towards our goal in a natural controlled way. As an additional benefit we can now control the shoulders and hips (we call these “keyjoints”) separately which allows us to do much more realistic movement. For example, if we let go with our right hand we can also stop the force applied on the right shoulder making that shoulder drop down in a realistic way. We can even simulate our character’s abs by allowing one keyjoint to influence another. So even if your right hand isn’t gripping anything as long as you have your feet planted firmly they can still apply a force on the right shoulder moving it towards its target position, simulating using your abs and back muscles.

There is one final issue to solve though. Because moving the character around this way by using more force the further a keyjoint is away from its target causes our movement to be jiggly and not rigid like you would see in a real climber. Almost like our character is attached to an invisible target with… an… elastic… band… Wiggles

NO MORE WIGGLES

Our first approach to making the movement look more natural and rigid was to simply reset the velocity of the rigidbody every frame and then apply a new force. Doing this we were able to completely remove the weird wiggly movement of our character. And it worked very well for a long time. But while it looked much better than before, it never looked completely natural. Which makes sense, because nature doesn’t work this way. Our character was completely negating gravity or any other outside forces. She was perfectly rigid as long as she was holding the wall. Of course when she let go we let gravity take over again so it looked pretty ok, but we were never quite satisfied with it.

At some point we were due for another overhaul of our climbing system and this gravity reset behaviour was one of the biggest issues we wanted to fix. The biggest thing we improved was changing from an arbitrary force based system to defining all of the forces in joules. The amount of joules from kinetic energy can be calculated by doing:

$$ KE = {1 \over 2} m v^2 $$

Instead of simply ignoring outside forces, this time we calculate the amount of work required to counteract those outside forces. To allow us more control we split our force calculation into two steps. Apply a force to try to negate our current velocity Add a force to our current velocity (whatever it is) to move towards the target

Every keyjoint has a budget defined in joules to apply these forces and we can also determine what percentage of that budget is used for those steps. So for instance, let’s say that our left shoulder has a budget of 500 joules. We configured it to use max 20% for the first step and the rest can be used for the second step. That means we can first use max 100 joules to counteract the current forces (like gravity) to try to get our shoulder’s velocity to 0. Then in the next step we use the remaining 400 joules to move our shoulder towards its goal. Keep in mind that these steps happen for all the keyjoints every frame, so outside forces like gravity are continuously being counteracted by all joints.

Spheres Climbing

Doing this made our climber look and feel much more natural. You could see the gravity subtly influence the player’s movement and it really felt like our character had to struggle to make certain moves. The climbing system became much more realistic. Additionally, in theory this allows for more interesting custom behaviour such as wind or climbing on moving structures which is very cool!

In the final installment of this series we will discuss how we calculate the player’s grip based on their body and hand position and how that influences the amount of force that can be applied for climbing.

Related articles