嗨,我的 2D 游戏角色传送得高了一点,然后他下降得很慢,当我按下跳跃按钮时,他就像一片树叶

Hi, my 2D game character teleport a little bit higher, and then he come down very slow, like a leaf when i press the jump button

enter image description here

如果我一直按下按钮,它会一直上升。当我删除用于向左移动或向右移动的脚本时,效果很好,但是当我添加它时,我遇到了这个问题。 这是我的代码

` { Rigidbody2D rb;

float dirX;
float jumpForce = 300f;
float moveSpeed = 5f;







void Start()
{
    rb = GetComponent<Rigidbody2D>();
}
void Update()
{
    dirX = CrossPlatformInputManager.GetAxis("Horizontal");
    rb.velocity = new Vector2(dirX * 10, 0);

    

    if (CrossPlatformInputManager.GetButtonDown("Jump"))
        DoJump();
}  
    void DoJump()
    {
        if (rb.velocity.y == 0)
            rb.AddForce(new Vector2(0, jumpForce), ForceMode2D.Force);
    } 
    
}`

rb.velocity = new Vector2(dirX * 10, rb.velocity.y);

rb.AddForce(new Vector2(rb.velocity.x, jumpForce), ForceMode2D.Force);

是的,只需要做这些更改

rb.velocity = new Vector2(dirX * 10, rb.velocity.y);

rb.AddForce(new Vector2(rb.velocity.x, jumpForce), ForceMode2D.Force);