簡體   English   中英

嗨,我的 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

在此處輸入圖像描述

如果我繼續按下按鈕,它會繼續上升。 當我刪除用於向左移動的腳本時,它工作得很好,但是當我添加它時,我遇到了這個問題。 這是我的代碼

` { 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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM