When doing the inverse kinematics for an arm reaching for a phone on a desk, we solve how to move and rotate your joints such that your hand ends up on the phone. Perhaps the most common use of IK is for walking animations on uneven surfaces, as we can raycast down to find the correct position a character’s foot must land and solve the displacement and angles for our leg’s joints and bones. Towards the start of the VR version of Buggy Allstars, this is what I was working on for a bit. I've always found techniques like Inverse Kinematics particularly interesting as it allows for a more visually consistent and immersive experience in animations and game kinematics without much code (and a little bit of trigonometry). Despite that, I still want to give artists and designers flexibility within this system to tweak certain parameters whenever possible.
To create our GLaDOS-like robot arm we can make a hierarchy of joint game objects such that the Origin Joint has child Joint 1, Joint 1 has child Joint 2, and Joint 2 has the child Hand. The implementation so far…
The new update function with smoothing prevents undesirable jagged movements. I initially tried to detect fast changes in the angle to try and create such a smoothing effect, but this is already done within the ‘speed’ parameter in SmoothDampAngle. This makes our robot arms look like skillful artists if we give it something to draw.
The 3D implementation extended pretty naturally, with the problem now having three degrees of freedom. While we did come to a place with the implementation that yielded minimal hiccups, we eventually switched to a much more sophisticated IK package that worked out of the box for VR. I would eventually come back during quarantine to take a closer look, especially in regards to the complexity an extra degree of freedom adds. There are infinitely many solutions that result in a hand or leg reaching the target position, as we can rotate about the axis to the target without changing the final position. This can result in arbitrary solutions looking anywhere from funny to terrifying and physically impossible.
We can find an arbitrary solution that is close to a desired pose that would be made by the artists. We would do this by minimizing the angle between an arbitrary solution found and the artist’s pose around this axis. Analytically, we can do this using quaternions.
Currently, most methods of modelling IK problems rely on numerical solutions, a lot of which I have covered in my Computational Physics courses. Probably the most flexible numerical approaches rely on iterative optimizations as there is always the possibility of an empty solution space from inverting forward kinematics equations. The most interesting one I came across was a ganja.js example that uses relaxation steps that minimizes the differences on all the remaining degrees of freedom. This heuristic method has comparatively very low computational cost, and is used extensively in FABRIK. When time allows, I’ll take a look at using the Newton-Raphson method with the jacobian inverse technique for a different numerical approach.