unity3d Unity2d:添加动画时播放器停止移动

w41d8nur  于 2023-01-13  发布在  其他
关注(0)|答案(1)|浏览(267)

我有一个统一的问题,球员的运动是很好的,直到我添加一个动画球员停止移动,即使我按下键盘键,当我删除动画补偿球员移动正常没有问题!
我试着将动画脚本与运动脚本分开,但仍然有同样的问题,我不认为问题来自代码播放器动画代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class playerAnim : MonoBehaviour
{
    Animator anim;
    Rigidbody2D rb;
    void Start()
    {
        rb = gameObject.GetComponent<Rigidbody2D>();
        anim = gameObject.GetComponent<Animator>();
    }
    void FixedUpdate()
    {
        if (rb.velocity.x == 0)
            anim.SetBool("isRunning", false);
        else
            anim.SetBool("isRunning", true);
        if (rb.velocity.y > 0)
            anim.SetBool("isJumping", true);
        else
            anim.SetBool("isJumping", false);
    }
}

播放器移动脚本

using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class playerControl : MonoBehaviour
    {
        Rigidbody2D rb;
        private float horizontal;
    
        public float runSpeed;
        public float jumpPower;
        public  bool inTheGround;
        private SpriteRenderer sp;
        Animator anim;
    
        // Start is called before the first frame update
        void Start()
        {
            rb = gameObject.GetComponent<Rigidbody2D>();
            sp = gameObject.GetComponent<SpriteRenderer>();
            anim = gameObject.GetComponent<Animator>();
        }
        private void Update()
        {
            horizontal = Input.GetAxisRaw("Horizontal");
    
        }
        private void FixedUpdate()
        {
            rb.velocity = new Vector2(horizontal * runSpeed, 
            rb.velocity.y);
         
        
    
            if (Input.GetButton("Jump")&& inTheGround)
            {
                
                rb.velocity = new Vector2(rb.velocity.x,jumpPower);
            }
            flipping();
            Debug.Log(rb.velocity.x);
    
        }
        private void OnCollisionEnter2D(Collision2D other)
        {
            if (other.gameObject.CompareTag("ground"))
                inTheGround = true;
        }
        private void OnCollisionExit2D(Collision2D other)
        {
            if 
           (other.gameObject.CompareTag("ground")&&rb.velocity.y>0.1)
                inTheGround = false;
        }
        void flipping()
        {
            if (Input.GetKey(KeyCode.RightArrow))
                sp.flipX = false;
            if (Input.GetKey(KeyCode.LeftArrow))
                sp.flipX = true;
        }
       }
uyhoqukh

uyhoqukh1#

检查动画组件上的Apply Root Motion是否设置为false。此设置可以覆盖对象位置随时间的变化。如果没有-您能否提供更多信息,完美的播放器组件的屏幕截图,和动画控制器。

相关问题