-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeadController.cs
46 lines (37 loc) · 1.09 KB
/
HeadController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using UnityEngine;
using System;
using System.Collections;
[RequireComponent(typeof(Animator))]
public class HeadController : MonoBehaviour
{
protected Animator animator;
public bool ikActive = false;
public Transform lookObj = null;
public float lookWeight = 2f;
void Start()
{
animator = GetComponent<Animator>();
}
//a callback for calculating IK
void OnAnimatorIK()
{
if (animator)
{
//if the IK is active, set the position and rotation directly to the goal.
if (ikActive)
{
// Set the look target position, if one has been assigned
if (lookObj != null)
{
animator.SetLookAtWeight(lookWeight);
animator.SetLookAtPosition(lookObj.position);
}
}
//if the IK is not active, set the position and rotation of the hand and head back to the original position
else
{
animator.SetLookAtWeight(0);
}
}
}
}