移除突然的动画变化
Remove sudden animation change
我有以下代码,效果很好。我的意思是...很好。唯一的问题是,当动画状态切换时,它非常急促和突然,而且看起来一点也不自然。有谁知道我该如何解决?提前致谢!!!
//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;
}
您正在寻找的是 Blend Tree, which, combined with Animator,它根据您定义的变量在动画之间平滑淡入淡出。我无法重写您的整个代码并设置您的混合树,但这里是一个起点:
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);
}
}
}
我有以下代码,效果很好。我的意思是...很好。唯一的问题是,当动画状态切换时,它非常急促和突然,而且看起来一点也不自然。有谁知道我该如何解决?提前致谢!!!
//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;
}
您正在寻找的是 Blend Tree, which, combined with Animator,它根据您定义的变量在动画之间平滑淡入淡出。我无法重写您的整个代码并设置您的混合树,但这里是一个起点:
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);
}
}
}