【问题标题】:Jumping up quicker? (Paper Mario style jump)跳得更快? (纸马里奥风格跳跃)
【发布时间】:2020-07-22 20:59:08
【问题描述】:

所以,Paper Marios jump 需要 8 帧才能达到最大跳跃高度,需要 12 帧才能回到地面。这很不寻常,知道如何用刚体快速跳起来吗?

我尝试在刚体.velocity.y > 0 时添加强制,但没有成功。

任何帮助将不胜感激,在此先感谢!

        //Jump when pressing button and on ground
        //jumpForce is a public float variable

    if (Input.GetButtonDown("Jump") && isGrounded)
    {
        theRB.velocity += new Vector3(0, jumpForce, 0);
    }

【问题讨论】:

标签: c# unity3d vector gravity


【解决方案1】:

如果没有刚体,使用 s = vt+1/2gt^2 ,你可以在上升时更改 Time.deltaTime 像这样:

public class BCDE : MonoBehaviour
{
    float v = 10;
    float g = -9.8f;
    float t = 0;
    bool go;

    [EasyButtons.Button]
    public void GO()
    {
        go = true;
    }

    private void Update()
    {
        if (go)
        {
            if (v * t >= (1f / 2f * g * t * t))
            {
                t += Time.deltaTime * 1.5f ;// 12 frame / 8 frame = 1.5 ( quick 1.5 times
            }
            else
            {
                t += Time.deltaTime;
            }

            float s = v * t + (1f / 2f * g * t * t);
            if(s <= 0)
            {
                go = false;
                transform.position = Vector3.zero;
                t = 0;
                return;
            }

            transform.position = new Vector3(0, s, 0);
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-16
    • 1970-01-01
    • 1970-01-01
    • 2013-05-14
    相关资源
    最近更新 更多