using UnityEngine;
using System.Collections;
public class CtrlIK : MonoBehaviour {
Animator anim;
public Transform enemy;
bool lookAtTarget;
RaycastHit hitInfo;
AvatarIKGoal aIKGoal=AvatarIKGoal.LeftHand ; //IK可动的身体部分
Transform goalTran;
// Use this for initialization
void Start () {
anim=GetComponent<Animator>();//寻找animator脚本
goalTran =GameObject.Find ("pickupWrench").transform ;
}
// Update is called once per frame
void FixedUpdate () {
if(Input.GetKey (KeyCode.G))
{
//anim.SetLookAtWeight (0,0,1,0,0.5f);
anim.SetLookAtWeight (0.5f);
anim.SetLookAtPosition (enemy.position );
}
}
float weightV=0;
void OnAnimatorIK()
{
Ray myRay=Camera.main.ScreenPointToRay (Input.mousePosition);
if(Physics.Raycast(myRay,out hitInfo))
{
if(hitInfo.transform ==goalTran)
{
//anim.SetBool ("Grab",true );
Debug.Log ("Drag me");
if(Input.GetMouseButton (0))
{
goalTran.Translate (goalTran.forward*Time.deltaTime *0.1f );
}
anim.SetIKPositionWeight (AvatarIKGoal.RightHand ,0.2f);
anim.SetIKPosition (AvatarIKGoal.RightHand ,goalTran.position );
}
if(hitInfo.transform.name =="_collision_main_001")
{
if(Input.GetMouseButton (0))
{
Debug.Log (hitInfo.transform.name );
anim.SetIKPosition (AvatarIKGoal.RightFoot,hitInfo.point );
weightV=Mathf.Lerp (weightV,1,Time.deltaTime );
anim.SetIKPositionWeight (AvatarIKGoal.RightFoot,weightV);
}
else
{
anim.SetIKPosition (AvatarIKGoal.RightFoot,hitInfo.point );
weightV=Mathf.Lerp (weightV,0,Time.deltaTime );
anim.SetIKPositionWeight (AvatarIKGoal.RightFoot,weightV);
}
}
}
}
void OnTriggerEnter()
{
anim.SetTrigger ("");
}
}
SetIKPositionWeight--OnAnimatorIK 一起使用
最新推荐文章于 2025-02-22 23:34:54 发布