1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Unityで関節PositionのみでAnimatorを動かす

Last updated at Posted at 2019-04-05

#Unityで関節PositionのみでAnimatorを動かす

SAFullBodyIK

をダウンロード、Unityへ入れる

SAFullBodyIK-master/Scripts/FullBodyIKBehaviourを使いたいHumanoidに張り付け

以下のBoneに使いたいHumanoidの関節を設定
Bone.PNG

これでHumanoidについているFullBody以下を動かせばHumanoidが動く。
EffectorのElbowやKneeについているPosをチェックするとKneeやElbowも動かせる。
ss.PNG

以下、Targetヒューマノイドの動きをPositionベースでまねるスクリプト。

using UnityEngine;
public class AnimationFromPositionWithFbik : MonoBehaviour {
    public Animator target;
    Animator animator;

	// Use this for initialization
	void Start () {
        animator = GetComponent<Animator>();
	}
	
	// Update is called once per frame
	void Update () {
        this.transform.position = ChangeP(target.transform.position);

        GameObject fullBIK = this.transform.Find("FullBodyIK").gameObject;
        foreach(IKset ik in IKsets)
        {
            fullBIK.transform.Find(ik.getI()).position = ChangeP(target.GetBoneTransform(ik.getB()).position);
        }
    }
    Vector3 ChangeP(Vector3 v)
    {
        return new Vector3(v.x -0.5f, v.y, v.z);
    }
    struct IKset
    {
        HumanBodyBones bone;
        string IKbone;
        public string getI(){ return IKbone; }
        public HumanBodyBones getB() { return bone; }
        public IKset(HumanBodyBones b, string ik) { bone = b; IKbone = ik; }
    }

    IKset[] IKsets = new IKset[]
    {
        new IKset(HumanBodyBones.Hips,"Hips"),
        new IKset(HumanBodyBones.RightLowerLeg,"RightKnee"),
        new IKset(HumanBodyBones.RightFoot,"RightFoot"),
        new IKset(HumanBodyBones.LeftLowerLeg,"LeftKnee"),
        new IKset(HumanBodyBones.LeftFoot,"LeftFoot"),
        new IKset(HumanBodyBones.Neck,"Hips/Neck"),
        new IKset(HumanBodyBones.Head,"Hips/Neck/Head"),
        new IKset(HumanBodyBones.LeftShoulder,"Hips/LeftArm"),
        new IKset(HumanBodyBones.LeftLowerArm,"Hips/LeftElbow"),
        new IKset(HumanBodyBones.LeftHand,"Hips/LeftWrist"),
        new IKset(HumanBodyBones.RightShoulder,"Hips/RightArm"),
        new IKset(HumanBodyBones.RightLowerArm,"Hips/RightElbow"),
        new IKset(HumanBodyBones.RightHand,"Hips/RightWrist"),

    };
  
}

似た動きはするが精度はまちまち
##参考
http://onoty3d.hatenablog.com/entry/2015/06/05/194010
https://qiita.com/keel/items/0d64167850566586d22a

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?