@Mecanim-Dev I have the IK working In Editor now using the IK goals created. I simply dropped it on my Avatar root where the Animator is. (should I be doing something different?) I substituted my avatar IK goals and they did not work. Do I just get rid of their creation in the Start() function? Also… Great you replied just minutes ago because just minutes ago i added the elbow and knee hints to the script and indeed they do react to them…meaning my internal avatar pole vectors per limb. However now I cannot adjust their position in Editor…This one last deal or understanding of it will make this super sweet for my and I am sure many others purposes. Here is my script…with sliders for adjusting weights.
edit : Just found out that even when I shut the script off and adjust the elbow hints that they snap back to the previous position whether the enableIK bool is set to true or not. What is the trick here?
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class EditorIK : MonoBehaviour {
Animator animator;
public bool enabledIK = false;
//IK Goals
public GameObject leftFootIKGoal = null;
public GameObject rightFootIKGoal = null;
public GameObject leftHandIKGoal = null;
public GameObject rightHandIKGoal = null;
//Pole Vectors
public GameObject leftKneeHint;
public GameObject rightKneeHint;
public GameObject leftElbowHint;
public GameObject rightElbowHint;
[Range(0.0f, 1.0f)]
public float leftFootPositionWeight = 0;
[Range(0.0f, 1.0f)]
public float rightFootPositionWeight = 0;
[Range(0.0f, 1.0f)]
public float leftHandPositionWeight = 0;
[Range(0.0f, 1.0f)]
public float rightHandPositionWeight = 0;
[Range(0.0f, 1.0f)]
public float rightElbowHintWeight = 0;
[Range(0.0f, 1.0f)]
public float leftElbowHintWeight = 0;
[Range(0.0f, 1.0f)]
public float leftFootRotationWeight = 0;
[Range(0.0f, 1.0f)]
public float rightFootRotationWeight = 0;
[Range(0.0f, 1.0f)]
public float leftHandRotationWeight = 0;
[Range(0.0f, 1.0f)]
public float rightHandRotationWeight = 0;
[Range(0.0f, 1.0f)]
public float rightKneeHintWeight = 0;
[Range(0.0f, 1.0f)]
public float leftKneeHintWeight = 0;
protected GameObject CreateIKGoal(string name)
{
GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
obj.name = name;
obj.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
return obj;
}
// Use this for initialization
void Start () {
animator = GetComponent<Animator>();
if (leftFootIKGoal == null) leftFootIKGoal = CreateIKGoal("LeftFootGoal");
if (rightFootIKGoal == null) rightFootIKGoal = CreateIKGoal("RightFootGoal");
if (leftHandIKGoal == null) leftHandIKGoal = CreateIKGoal("LeftHandGoal");
if (rightHandIKGoal == null) rightHandIKGoal = CreateIKGoal("RightHandGoal");
}
// Update is called once per frame
void Update () {
Debug.Log("EditorIK.Update()");
animator.Update(0);
}
void OnAnimatorIK(int layerIndex)
{
Debug.Log("EditorIK.OnAnimatorIK()");
animator.SetIKPositionWeight(AvatarIKGoal.LeftFoot, leftFootPositionWeight);
animator.SetIKHintPositionWeight (AvatarIKHint.LeftKnee, leftKneeHintWeight);
animator.SetIKPositionWeight(AvatarIKGoal.RightFoot, rightFootPositionWeight);
animator.SetIKHintPositionWeight (AvatarIKHint.RightKnee, rightKneeHintWeight);
animator.SetIKPositionWeight(AvatarIKGoal.LeftHand, leftHandPositionWeight);
animator.SetIKHintPositionWeight (AvatarIKHint.LeftElbow, leftElbowHintWeight);
animator.SetIKPositionWeight(AvatarIKGoal.RightHand, rightHandPositionWeight);
animator.SetIKHintPositionWeight (AvatarIKHint.RightElbow, rightElbowHintWeight);
animator.SetIKRotationWeight(AvatarIKGoal.LeftFoot, leftFootRotationWeight);
animator.SetIKRotationWeight(AvatarIKGoal.RightFoot, rightFootRotationWeight);
animator.SetIKRotationWeight(AvatarIKGoal.LeftHand, leftHandRotationWeight);
animator.SetIKRotationWeight(AvatarIKGoal.RightHand, rightHandRotationWeight);
if (enabledIK)
{
animator.SetIKPosition(AvatarIKGoal.LeftFoot, leftFootIKGoal.transform.position);
animator.SetIKRotation(AvatarIKGoal.LeftFoot, leftFootIKGoal.transform.rotation);
animator.SetIKPosition(AvatarIKGoal.RightFoot, rightFootIKGoal.transform.position);
animator.SetIKRotation(AvatarIKGoal.RightFoot, rightFootIKGoal.transform.rotation);
animator.SetIKPosition(AvatarIKGoal.LeftHand, leftHandIKGoal.transform.position);
animator.SetIKRotation(AvatarIKGoal.LeftHand, leftHandIKGoal.transform.rotation);
animator.SetIKPosition(AvatarIKGoal.RightHand, rightHandIKGoal.transform.position);
animator.SetIKRotation(AvatarIKGoal.RightHand, rightHandIKGoal.transform.rotation);
}
else
{
leftFootIKGoal.transform.position = animator.GetIKPosition(AvatarIKGoal.LeftFoot);
leftFootIKGoal.transform.rotation = animator.GetIKRotation(AvatarIKGoal.LeftFoot);
rightFootIKGoal.transform.position = animator.GetIKPosition(AvatarIKGoal.RightFoot);
rightFootIKGoal.transform.rotation = animator.GetIKRotation(AvatarIKGoal.RightFoot);
leftHandIKGoal.transform.position = animator.GetIKPosition(AvatarIKGoal.LeftHand);
leftHandIKGoal.transform.rotation = animator.GetIKRotation(AvatarIKGoal.LeftHand);
rightHandIKGoal.transform.position = animator.GetIKPosition(AvatarIKGoal.RightHand);
rightHandIKGoal.transform.rotation = animator.GetIKRotation(AvatarIKGoal.RightHand);
}
}
}
Thank you very much for any clarification you can offer. Mecanim rocks my face off. I can finally put together the procedural IK kata rig training system I developed over a few years in C4D in Unity and will be releasing it to the Asset Store soon.