質問編集履歴
1
スクリプトを追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,6 +28,104 @@
|
|
28
28
|
|
29
29
|
Animatorのアバターにはヒューマノイドを使っています。アニメーション自体はアセットストアから入手したものです。
|
30
30
|
|
31
|
+
ソースコードは以下です。Unityの公式リファレンスにあるものを使いました。
|
32
|
+
|
33
|
+
```C#
|
34
|
+
|
35
|
+
protected Animator animator;
|
31
36
|
|
32
37
|
|
38
|
+
|
39
|
+
public bool ikActive = false;
|
40
|
+
|
41
|
+
public Transform rightHandObj = null;
|
42
|
+
|
43
|
+
public Transform lookObj = null;
|
44
|
+
|
45
|
+
void Start()
|
46
|
+
|
47
|
+
{
|
48
|
+
|
49
|
+
animator = GetComponent<Animator>();
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
// IK を計算するためのコールバック
|
56
|
+
|
57
|
+
void OnAnimatorIK()
|
58
|
+
|
59
|
+
{
|
60
|
+
|
61
|
+
if (animator)
|
62
|
+
|
63
|
+
{
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
// IK が有効ならば、位置と回転を直接設定します
|
68
|
+
|
69
|
+
if (ikActive)
|
70
|
+
|
71
|
+
{
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
// すでに指定されている場合は、視線のターゲット位置を設定します
|
76
|
+
|
77
|
+
if (lookObj != null)
|
78
|
+
|
79
|
+
{
|
80
|
+
|
81
|
+
animator.SetLookAtWeight(1);
|
82
|
+
|
83
|
+
animator.SetLookAtPosition(lookObj.position);
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
// 指定されている場合は、右手のターゲット位置と回転を設定します
|
90
|
+
|
91
|
+
if (rightHandObj != null)
|
92
|
+
|
93
|
+
{
|
94
|
+
|
95
|
+
animator.SetIKPositionWeight(AvatarIKGoal.RightHand,1);
|
96
|
+
|
97
|
+
animator.SetIKRotationWeight(AvatarIKGoal.RightHand,1);
|
98
|
+
|
99
|
+
animator.SetIKPosition(AvatarIKGoal.RightHand, rightHandObj.position);
|
100
|
+
|
101
|
+
animator.SetIKRotation(AvatarIKGoal.RightHand, rightHandObj.rotation);
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
//IK が有効でなければ、手と頭の位置と回転を元の位置に戻します
|
112
|
+
|
113
|
+
else
|
114
|
+
|
115
|
+
{
|
116
|
+
|
117
|
+
animator.SetIKPositionWeight(AvatarIKGoal.RightHand, 0);
|
118
|
+
|
119
|
+
animator.SetIKRotationWeight(AvatarIKGoal.RightHand, 0);
|
120
|
+
|
121
|
+
animator.SetLookAtWeight(0);
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
```
|
130
|
+
|
33
131
|
情報が少なく恐縮ですがよろしくお願いします。
|