移除突然的动画变化

问题描述 投票:0回答:1

我有下面的代码,它的工作非常好。我的意思是... 很好 唯一的问题是,当动画状态切换时,它非常前卫和突然,它看起来一点也不自然。有谁知道如何解决这个问题吗?先谢谢你!!!

//this runs in Update()
if (Input.GetKey(KeyCode.Space) || jumped) {
        if (!characterController.isGrounded)
            jumped = true;
        else
            jumped = false;

        if (jumped) {
            animator.Play("jump");
            return;
        }
    }
    if (characterController.velocity == Vector3.zero) {
        animator.Play("idle");
        if (!weaponEquipped && !switchingWeapon)
            animator.Play("idleArms", 1);
        return;
    } else if (Input.GetKey("a")) {
        if (isRunning && !vitals.isEmpty("stamina")) {
            animator.Play("runLeft");
            return;
        }
        animator.Play("walkLeft");
        return;
    }
    if (Input.GetKey("d")) {
        if (isRunning && !vitals.isEmpty("stamina")) {
            animator.Play("runRight");
            return;
        }
        animator.Play("walkRight");
        return;
    } else if (Input.GetKey("s")) {
        if (isRunning && !vitals.isEmpty("stamina")) {
            animator.Play("runBack");
            if (!weaponEquipped && !switchingWeapon)
                animator.Play("runBackArms", 1);
            return;
        }
        animator.Play("walkBack");
        if (!weaponEquipped && !switchingWeapon)
            animator.Play("walkBackArms", 1);
        return;
    } else if (isRunning && !vitals.isEmpty("stamina")) {
        animator.Play("run");
        if (!weaponEquipped && !switchingWeapon)
            animator.Play("runArms", 1);
        return;
    } else {
        animator.Play("walk");
        if (!weaponEquipped && !switchingWeapon)
            animator.Play("walkArms", 1);
    } if (!isRunning && characterController.velocity.magnitude > 0) {
        animator.Play("walk");
        return;
    }
c# unity3d animation animator
1个回答
0
投票

你要找的是一个 混合树,再加上 动画师,根据你定义的变量,在动画之间平滑淡入。我不能重写你的整个代码并设置你的Blend Tree,但这里是一个起点。

using UnityEngine;
using System.Collections;
using System.Collections.Generics;

public class YourClass: MonoBehaviour
{
   public Animator animator;

   float vertical = 0f;
   float horizontal = 0f;

   void Update()
   {
      if (Input.GetButtonDown("Jump"))
      {
         animator.SetTrigger("Jump");
      }
      else
      {
         vertical = Input.GetAxis("Vertical");
         horizontal = Input.GetAxis("Horizontal");

         animator.setFloat("Vertical Movement", vertical);
         animator.setFloat("Horizontal Movement", horizontal);
      }
   }
}
© www.soinside.com 2019 - 2024. All rights reserved.