IK howto

Hi Guys,

I am looking into how to use IK on our main character (humanoid) to fix some small offsets on the hands, due to additive animations.

I have been reading the forums, and looked a bit at IK files inside the Locomotion system.

http://forum.unity3d.com/viewtopic.php?t=6360&highlight=inverse+kinematic

It seems that IKSimple.cs and IKSolver.cs has some content, but im wonder if there is a simpler approach to achieve runtime IK?

Kind regards

/tax

they are actually the easiest solution as you need to do it fully within Unity and simulate it yourself.

Hi guys!

I tried to hack and slash some code from unity’s Locomotion example, and quite fast I came up with a solution.

Im not sure its the way to go, but got me some of the way.

using UnityEngine;
using System.Collections;

public class IMIK : MonoBehaviour {
	
	// Get the chain of transforms from one transform to a descendent one
	public Transform[] GetTransformChain(Transform upper, Transform lower) {
		Transform t = lower;
		int chainLength = 1;
		while (t != upper) {
			t = t.parent;
			chainLength++;
		}
		Transform[] chain = new Transform[chainLength];
		t = lower;
		for (int j=0; j<chainLength; j++) {
			chain[chainLength-1-j] = t;
			t = t.parent;
		}
		return chain;
	}
	
	public Transform target;
	public Transform from;
	public Transform to;
	private IKSolver ikSolver;
	public Color debugColor;
	
	// Use this for initialization
	void Start () {
		//ikSolver = new IKSimple();
		ikSolver = new IK1JointAnalytic();
	}
	
	void LateUpdate () {
		ikSolver.Solve( GetTransformChain(from, to), target.position );
	}
}

This does not include limits or orientation of the bones.

Any ideas for doing that?

Kind regards

/tax

P.S:
I was thinking of two scripts, that I would find usefull. Perhaps some of you already made them.

  1. A component that draws the bones of a skeleton as lines.

  2. A pose checksum generator.

It would be handy if I could get a checksum of the sum of orientations recursively through a skeleton.

This would allow me to check if poses are identical.

Especially handy when working with many layers of additive animation.

E.g: Check that first and last frame is identical to my centerpose.

[/code]