LoginSignup
19
16

More than 5 years have passed since last update.

Final IKで遊んでみる ~ペットを手なずけてみた~

Posted at

3057.png

セールのときに購入したままままほったらかしていたので使ってみます

ドキュメントによると

  • Aim IK
  • Biped IK
  • CCD IK
  • FABRIK
  • FABRIK Root
  • Full Body Biped IK
  • Limb IK
  • Look At IK
  • Trigonometric IK
  • Interaction System
  • Grounder
  • Rotation Limits

とカテゴリわけされていたのでわかりやすそうなのから試していってみようかと思います
今回はBipedIKあたりです

こんな感じに餌につられる可愛いペットができます。

Biped IK下準備

まずはAnimation TypeがGenericかHumanoidのmodelを画面上に配置
AnimatorのControllerをセットし、BipedのScriptをアタッチ
スクリーンショット 2016-06-20 15.32.08.png

自動でセットされますが、
自動で綺麗にセットされなかった場合は手動でアタッチする必要があります。
スクリーンショット 2016-06-20 15.32.16.png

首振り

首振り自体はシンプルで、
BipedIKvsAnimatorIK.csのスクリプトを参考に
bipedIKが先ほどセットしたbipedIKをセット。lookAtは見るオブジェクト
からのGameObjectなどをつくってアタッチすればOK

その下はオブジェクトが動いたときに体などがどれくらい動くか。
1だと動いて0だと全く動かなくなります。
ターゲットを動かしたときに体全体が動いちゃう場合などは
lookAtBodyWeightを0とかにしてあげればOK

public class NeckMove: MonoBehaviour {

    //public Animator animator;
    public BipedIK bipedIK;

    // Look At
    public Transform lookAtTargetBiped;

    public float lookAtWeight = 1f;
    public float lookAtBodyWeight = 1f;
    public float lookAtHeadWeight = 1f;
    public float lookAtEyesWeight = 1f;
    public float lookAtClampWeight = 0.5f;
    public float lookAtClampWeightHead = 0.5f;
    public float lookAtClampWeightEyes = 0.5f;


    //void OnAnimatorIK(int layer) {
    void Update() {

        bipedIK.SetLookAtPosition(lookAtTargetBiped.position);
        bipedIK.SetLookAtWeight(lookAtWeight, lookAtBodyWeight, lookAtHeadWeight, lookAtEyesWeight, lookAtClampWeight, lookAtClampWeightHead, lookAtClampWeightEyes);
    }
}

手とかを追従させるにはこんな感じでいけます。


    // Hand
    public Transform handLeftTargetBiped;
    public float handPositionWeight = 0f;
    public float handRotationWeight = 0f;

    void Update() {
        bipedIK.SetIKPosition(AvatarIKGoal.LeftHand, handLeftTargetBiped.position);
        bipedIK.SetIKRotation(AvatarIKGoal.LeftHand, handLeftTargetBiped.rotation);
        bipedIK.SetIKPositionWeight(AvatarIKGoal.LeftHand, handPositionWeight);
        bipedIK.SetIKRotationWeight(AvatarIKGoal.LeftHand, handRotationWeight);
    }


これは固定するやつだから、お手とかさせるのだったらまた違うやつだね・・・。

一旦ここまで

19
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
16