反向动力学 matlab IK,Unity动画系统之IK(反向动力学)动画

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class IK_test : MonoBehaviour {

Animator _animator;

public Transform sphereHead,sphereLeftFoot,sphereLeftHand;

bool isIK = true;

// Use this for initialization

void Start ()

_animator = transform.GetComponent();

private void Update()

if (Input.GetKeyDown(KeyCode.A))

isIK = false;

//启动IK动画的unity特定方法OnAnimatorIK(),IK Pass要勾选才行

private void OnAnimatorIK()

if (isIK)

//设置头部转向的权重,取值范围0-1,转动的幅度与数值呈正比(只有头部转动哦)

// _animator.SetLookAtWeight(0.2f);

//头部带动身体转动

_animator.SetLookAtWeight(1, 0.5f);

//设置权重的代码必须有,不然模型不响应

_animator.SetLookAtPosition(sphereHead.position);

//左脚跟随目标物位移 AatarIKGoal枚举 还有rightFoot,leftHand,rightHand

_animator.SetIKPositionWeight(AvatarIKGoal.LeftFoot, 1);

_animator.SetIKPosition(AvatarIKGoal.LeftFoot, sphereLeftFoot.position);

//左手跟随目标物旋转 AatarIKGoal枚举 还有rightFoot,leftHand,rightHand

_animator.SetIKRotationWeight(AvatarIKGoal.LeftHand, 1);

_animator.SetIKRotation(AvatarIKGoal.LeftHand, sphereLeftHand.rotation);

else

//模型复位,回到模型最初的状态

_animator.SetLookAtWeight(0);

_animator.SetIKPositionWeight(AvatarIKGoal.LeftFoot,0);

_animator.SetIKRotationWeight(AvatarIKGoal.LeftHand, 0);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值