Skip to content

IK Presence Creation

eisclimber edited this page Nov 3, 2024 · 4 revisions

Creating an IK Presence

Inverse Kinematics (IK) is a method to approximate the pose of the limbs and bones of a humanoid or robot using only a few target transforms. This is great for VR as it allows to approximate the actual player's body in VR from only their head and hands (and optionally more trackers).

Workflow

  1. This Setup-Dialog describes the creation of an Inverse Kinematic (IK) representation of a person for the ExPresS XR-Rig. The creation is not automated, and due to its complexity, it is a rather long process. ExPresS XR provides the necessary scripts and animations to make it as easy as possible. It also comes with a sample IK rig, both with and without a model. The latter only contains the basic structure and must be configured to match a model.
  2. First, a model of a person/humanoid is needed. It should be properly rigged, such as the models from Mixamo or Microsoft RocketBox. If you have an unrigged model, check out AccuRig. It is desireable that the model does not consist of just a single mesh. Rather head, eyes, hair, ... should be separate as the camera will be placed near/inside the model. This may cause some artifacts, which can be prevented in when having a separate model.   When you have found a model, import it.   Attention: Make sure to do so as a 'Humanoid' under the 'Rig'-Tab in the Inspector and apply the changes.
  3. Instance the model in your scene. Visualize the bones of your character using "Animation Rigging > Bone Render Setup". Add an IK Rig by selecting "Animation Rigging > Rig Setup" or using the empty IK Rig from ExPresS XR.   The Rig will need three empty GameObjects as children. Create and name them accordingly: 'Head', 'Left Arm' and 'Right Arm'.   The Head will have a 'Multi-Parent Constraint'-Component. Create an empty GameObject under the Head and name it 'Head_target'. Set the 'Head'-Bone of your rig as the 'Constrained Object' and the 'Head_target' as the only entry in 'Source Objects'. Whilst holding the 'Ctl' key, select first the 'Head_target' and then the 'Head'-Bone. Then select 'Animation Rigging > Align Transform' to align the first to the second.   For both arms, add a 'Two Bone IK Constraint'-Component. Set the left/right 'Hand'-Bone as 'Tip'. Hover over the name of the component at the top, right-click and select the 'Auto Setup from Tip Transform'-Option. This will set the other bones automatically and will create a target and a hint GameObject. Align the targets with the 'Hand'-Bones and hints with the 'Forearm'-Bones as done with the head. To let the arms bend correctly, move the hints a bit behind the elbows so that they are slightly outside the model.
  4. Add the IK Body Presence script to the root of your model. Set the 'Ik Targets' in the component to the references of the Head and Hand/Arm-Targets. Set the 'Vr Target' to the MainCamera and to the 'Interaction Controller' of your ExPresS XR Rig. Make sure the XR Rig's i configured to show a hand model.   Run the application, and the model should track, but all the wrong rotations and positions. Whilst the game is running, adjust 'positionOffset' and 'rotationOffset' of the hands. Be sure to save/copy then when exiting 'Play Mode'! The 'positionOffset' should be the same for both hands and only be negated in the x-coordinate. The 'rotationOffset' sadly behaves weird due to the IK constraints being enforced. For our Mixamo-Model the values were (-0.05, -0.02, -0.11) and (0, 90, 100) for the left and (0.05, -0.02, -0.11) and (0, 270, 260) for the right for position and rotation respectively.   The head might be tracked a bit behind as the Camera is tracked to a center position in front of the eyes but the 'Head'-Bones sits at the spine. To ensure correct behavior, DO NOT change the offsets in the component. Rather, add a GameObject as child of the MainCamera and set it as 'Vr Target'. Then move the GameObject such that the camera sits in front of the models eyes. Make sure to save it's position when exiting 'Play Mode'!
  5. The hand animations must be played on the model. The file "Assets/ExPresS XR/IK/Animations/Humanoid Hand Animations" provides the animations for Idle, Grab and Pinch. If you want to use your own Animations, they must be created with an external program (e.g. Blender) due to Unity's restriction. We highly advise against doing so (as it sucks). Reimport your model with a 'Generic'-Rig instead, and create Animations using Unity instead if desired. They will then work only for your model or one with the exact same rig.   Add an 'Animator'-Component to the root of your model if it does not already exist. Drag in the "Assets/ExPresS XR/IK/Animations/IK Character Animation Controller" as 'Controller'. Set the 'Avatar' to the one in your model. It can be accessed via the (>)-Icon in the file system on your imported model.   Then add two 'Single Hand Grip Animator'-Components to the root of your model. Set one to 'Left' and one to 'Right' with 'Trigger Prefix' "L_" and "R_" respectively.   Finally, switch 'Type of Hand Model' to none in the XR Rig, and your rig is ready to go.
  6. (Optional) Add the ability for the legs to bend according to the height of the VR headset (prevents clipping of the character into the floor). Add the 'IK Legs'-Component to the IK Presence GameObject. Make sure the Animator has a separate AnimationLayer for the lower body. It should have weight 1, its AvatarMask set to the 'Lower Body Avatar Mask' and the 'IK Pass'-option enabled. Adjust the 'feetOffset' during runtime such that the legs are in an upright position while standing, but also do not clip (too much) through the floor.
  7. (Optional) Feel free to add more constraints to the rig. You can also track additional input devices (like the HTC Vive Trackers) using the 'IKPositionTracker'-Component and setting it up similar to the 'IKBodyPresence'.

Common Issues

  • The system uses Unity's 'Humanoid'-Bone-Structure, so your models must be imported as such. This makes the system flexible, as animations can be mapped across all Humanoids. Sadly, the mapping of the animations can be a bit weird, in which case you will either need to create your own humanoid(!) animations, which need to be created in external programs like Blender. Alternatively, you can use a 'Generic' bone structure to use your own animations and edit them in Unity.
  • Be careful when renaming the Bones of your humanoid, as the hand animations might not work then... Another possibility is that your Animation Controller is missing or that your prefixes in the Single Hand Grip Animators are set incorrectly, but you will be warned in that case.
  • The RocketBox Characters come with an Editor-only Import-Script. This needs to be removed, as changes prevent the model from being imported as Humanoid (will change back to Generic automatically).

Limitations and FinalIK

Be aware that this implementation is only minimal and focuses more on the workflow using IK. ExPresS XR's IK scripts should be a free alternative to FinalIK. This plugin is generally a better option as it is the 'gold standard' for IK in Unity. It provides more reaistic IK aswell as more configuration options, but it comes at a cost of about €90. The workflow stays pretty much the same, but only uses FinalIK's 'VR IK'-Component instead of the 'IKBodyPresence'- and 'IKLegs'-Components. Also, take a look at the 'VRIKCalibrator' to calibrate the presence's to the player's height.

ExPresS XR Wiki

Tutorial Pages

Code Documentation

Clone this wiki locally