[英]3d Unity Player Object moves in the same direction
我有一個問題,玩家朝某個方向移動,但角色的 animation 保持不變。 因此,如果我單擊“w”鍵,播放器將向前運行 animation 作品。 但是當我向后單擊“s”時,角色不會旋轉到它只是移動/向后滑動的方向,角色面向前方並且沒有 animation。 請幫忙!!
public class Player : MonoBehaviour {
private Animator anim;
private CharacterController controller;
public float speed = 600.0f;
public float turnSpeed = 400.0f;
private Vector3 moveDirection = Vector3.zero;
public float gravity = 20.0f;
private Vector3 curLoc;
void Start () {
controller = GetComponent <CharacterController>();
anim = gameObject.GetComponentInChildren<Animator>();
}
void Update (){
if (Input.GetKey ("w")) {
anim.SetInteger ("AnimationPar", 1);
} else {
anim.SetInteger ("AnimationPar", 0);
}
if (Input.GetKey("s"))
{
anim.SetInteger("Condition", 1);
}
else
{
anim.SetInteger("Condition", 0);
}
if (controller.isGrounded){
moveDirection = transform.forward * Input.GetAxis("Vertical") * speed;
}
float turn = Input.GetAxis("Horizontal");
transform.Rotate(0, turn * turnSpeed * Time.deltaTime, 0);
controller.Move(moveDirection * Time.deltaTime);
moveDirection.y -= gravity * Time.deltaTime;
if (Input.GetKey(KeyCode.S))
{
}
}
}
您需要向 Animator 展示動畫是如何播放和過渡的。 只需在游戲播放時打開動畫器並檢查 animation 是否正在播放“條件”參數傳遞的位置。 檢查 animation 轉換。 另外,我建議您在按下“s”時將值“AnimationPar”更改為 0。
if (Input.GetKey("s"))
{
anim.SetInteger ("AnimationPar", 0);
anim.SetInteger("Condition", 1);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.