- Home /
Question by
jlgactionpinball · Mar 10, 2019 at 09:35 AM ·
animationunity 5scripting problem
How to set up IK control from another Game Object ?
Hi, I'm a very beginner. I'm trying to get my character to look at some objects in the scene. I would like to attach the script to the game objects. I've tried this to see how IK works with this script on my character :
public class IKControl : MonoBehaviour
{
protected Animator animator;
[Range(0.0f, 1.0f)]
public float ikLevel = 0;
public Transform lookObj = null;
void Start()
{
animator = GetComponent<Animator>();
}
void OnAnimatorIK()
{
animator.SetLookAtWeight(ikLevel);
animator.SetLookAtPosition(lookObj.position);
}
}
It works as expected. I've then tried to modify this script to be able to attach it to any game object, but it doesn't work :
public class IKControlObject : MonoBehaviour
{
public Transform player;
private Animator animator;
[Range(0.0f, 1.0f)]
public float ikLevel = 0;
public Transform lookObj = null;
void Start()
{
animator = player.GetComponent<Animator>();
}
void OnAnimatorIK()
{
animator.SetLookAtWeight(ikLevel);
animator.SetLookAtPosition(lookObj.position);
}
}
Could anybody help me ?
Comment