Unity - A计划(一年有效期) 扫二维码继续学习 二维码时效为半小时

(61评价)
价格: 2208.00元
unity中的动画系统的问题
猫懒发起了问答2018-10-19
4
回复
423
浏览

人物在碰到物体的时候没有跳跃,直接穿过去了。

这是代码

public class Player : MonoBehaviour
{

    private Animator anim;
    private int speedRotateID = Animator.StringToHash("SpeedRotate");
    private int speedZID = Animator.StringToHash("SpeedZ");
    private int VaultID = Animator.StringToHash("Vault");
    private Vector3 matchTarget = Vector3.zero;

    // Use this for initialization
    void Start()
    {
        anim = GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        anim.SetFloat(speedZID, Input.GetAxis("Vertical") * 4.1f);
        anim.SetFloat(speedRotateID, Input.GetAxis("Horizontal") * 126);
        bool isVault = false;
        if (anim.GetFloat(speedZID) > 3 && anim.GetCurrentAnimatorStateInfo(0).IsName("Locomotion"))
        {
            RaycastHit hit;
            if (Physics.Raycast(transform.position + Vector3.up * 0.3f, transform.forward, out hit, 4.5f))
            {
                if (hit.collider.tag == "Obstacle")
                {
                    if (hit.distance > 3)
                    {
                        Vector3 point = hit.point;
                        point.y = hit.collider.transform.position.y + hit.collider.bounds.size.y+0.1f;
                        matchTarget = point;
                        isVault = true;
                    }

                }
            }
        }
        anim.SetBool(VaultID, isVault);
        if (anim.GetCurrentAnimatorStateInfo(0).IsName("Vault"))
        {
            anim.MatchTarget(matchTarget, Quaternion.identity, AvatarTarget.LeftHand, new MatchTargetWeightMask(Vector3.one, 0), 0.38f, 0.5f);
        }
    }
}

然后之前没有用Matchtarger之前人物是可以跳跃的,就是之前这个代码

   void Update()
    {
        anim.SetFloat(speedZID, Input.GetAxis("Vertical") * 4.1f);
        anim.SetFloat(speedRotateID, Input.GetAxis("Horizontal") * 126);
        bool isVault = false;
        if (anim.GetFloat(speedZID) > 3 )
        {
            RaycastHit hit;
            if (Physics.Raycast(transform.position + Vector3.up * 0.3f, transform.forward, out hit, 4.5f))
            {
                if (hit.collider.tag == "Obstacle")
                {
                    if (hit.distance > 3)
                   
                        isVault = true;
                    

                }
            }
        }
        anim.SetBool(VaultID, isVault);

 

所有回复
发表回复
你还没有登录,请先 登录或 注册!