【Unity】はじめてのUnity IK
どもども、カヤック閃光部あまのです。
UnityでIKを実装することが出来ました!!
Unityサイトのリファレンスがわからなさすぎたのでブログで説明します。
骨とかリグの説明はこちら
まず、FBXで書き出されたキャラクターを読み込みUnityから球オブジェクトを作成しました。
C#でIKCtrlを作成して以下のスクリプトを記入します。
using UnityEngine; using System; using System.Collections; [RequireComponent(typeof(Animator))] public class IKCtrl : MonoBehaviour { protected Animator animator; public bool ikActive = false; public Transform rightHandObj = null; void Start () { animator = GetComponent<Animator>(); } void OnAnimatorIK(int layerIndex) { animator.SetIKPositionWeight(AvatarIKGoal.RightHand,1.0f); animator.SetIKRotationWeight(AvatarIKGoal.RightHand,1.0f); animator.SetIKPosition(AvatarIKGoal.RightHand,rightHandObj.position); animator.SetIKRotation(AvatarIKGoal.RightHand,rightHandObj.rotation); } }
キャラクターのInspectorから以下の画像のように設定する。
Animation Type:Hurmanoid
AvatarDefintion:Create From This Moel
次に、Animator Controllerを作成
InspectorのAnimator/ControllerにAnimator Controllerをアサイン
AnimatorからIK PASSにチェックを入れる。
これでOnAnimatorIKが実行されるようになります。
球をIKCtrlにアサインします。
完成した動画!!
はじめてのUnity IK from _perfect on Vimeo.