No point and click adventure game would be complete without the ability to pick up seemingly useless junk for use in some elaborate puzzle. The old game selected from a couple of animations, then just played them near the object. The end result meant the player had to use their imagination a little bit.
For this 3D remake, we had 3 options:
- Use the old method of playing a generic animation (sacrificing quality)
- Manually create an animation for every object pick-up (best quality, but extremely time consuming)
- Use code (IK) to manipulate the skeleton of the player model to pick up any object
Since time is a precious commodity when creating an indie game, we decided to go for a hybrid between 1 and 3, catch-all animations and code driven fine tuning of the player’s skeleton.
I’ll start by explaining the IK part of this system. In layman’s terms, IK (Inverse Kinematics) is figuring out how to place joints in a system (in this case the player’s skeleton) given a desired end position. I find it to be a difficult thing to explain with words, so allow me to demonstrate with some crudely drawn diagrams I made.
Here is an arm. It’s made up of 3 parts, and 2 joints; a hand, a lower arm, and an upper arm. The hand is connected to the lower arm and the lower arm is in turn connected to the upper arm.
This is a simplified version of the player skeleton in our game. Of course out player has a body and even various joints for his fingers, but for demonstrations sake, we’ll be using just these parts.
Let’s say the player came across a tasty-looking can of peas that we would very much like to pick up.
In order to pick up these delicious peas, we know where our hand needs to end up; grasping the can.
If we move our hand to where it needs to go, the arm needs to follow (unless your name is Rayman). This is where the power of IK comes in. Since the hand has moved, we need to update all of it’s children, in this case, the lower arm.
Now that we’ve moved the lower arm, we need to move it’s children as well, which in this case is just the upper arm. This usually continues all the way down the entire system until we hit a dead end.
This is the basic algorithm behind IK. For convenience I’ve included the steps in gif format below.
I will admit my experience with actually building IK systems myself is limited. In the past I have built an IK system for use in drawing rope like objects, where each segment is just a line and there are hundreds joined together in series. However the algorithm gets a little more complicated when you have multiple children and other considerations such as joint constraints (for example, the arm should be limited since elbows can’t bend backwards).
Since I’m not an expert on IK, I decided to get an off-the-shelf solution for use in Arrival in Hell. There are a few out there, but the one which is held in the highest regard is the excellent Final IK system. It’s a pleasure to use, has tonnes of different features and their support team has been very helpful.
My interaction system works like this:
- Using my Interactive Object system, the player moves to a target position (near the object he is picking up) and looks at the object
- A generic pick-up animation is played appropriate for the object (if the object is on a table, he just reaches out, if it’s on the floor, he bends down to pick it up)
- During the course of the animation, Final IK’s weight (how much it affects the hand position) is modified to blend between the animation and the IK controlled hand position.
- At the point the IK weight is 100%, we know the hand is positioned on the object, at this point the Unity GameObject is re-parented into the player’s hand. This way we no longer require IK to position the hand over the object, since it will permanently be attached.
- The animation finishes with the player placing his hand (now containing the object) over his pocket. Once the animation has completed, we hide the object (indicating the player has put it in his pocket)
This system isn’t as good as animating every pick-up animation by hand, but it is far quicker. In order to create a new object which can be picked up I:
- Copy an object and replace the model
- Change the parameters in my InteractiveObject script
- Reposition the ‘walk to’ target and hand skeleton target
- Swap the generic pick up animation if needed
This process is so fast, I have made a gif to demonstrate it!
It’s not the prettiest animation in the world, but it gets the job done. Here is how it looks in the game at the moment. Please excuse the character model glitching a bit; it’s a work in progress.
Thanks for reading. Please leave a comment if you have any questions about the topics covered in this week’s write-up. Next week I plan on writing about how our dialogue system works.