#Unityで関節PositionのみでAnimatorを動かす
をダウンロード、Unityへ入れる
SAFullBodyIK-master/Scripts/FullBodyIKBehaviourを使いたいHumanoidに張り付け
これでHumanoidについているFullBody以下を動かせばHumanoidが動く。
EffectorのElbowやKneeについているPosをチェックするとKneeやElbowも動かせる。
以下、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