跳跃

From Minecraft Parkour Wiki
This page is a translated version of the page Jumping and the translation is 100% complete.
Other languages:

跳跃是一个无须过多解释的基本机制。


触发

要开始跳跃,玩家必须在上一站在地面上。这就是为什么玩家能够从方块上跑出去 1 刻(例如用延立),并且仍然能够跳跃。

长按跳跃键时,玩家每 10 刻(0.5 秒)最多跳跃一次。

  • 当跳跃高度超过 0.75b 时,长按跳跃键不是最优的(手动按跳跃键会比长按速度更快)。
  • 松开跳跃键会重置冷却时间,使玩家能够在下一 tick 再次跳跃。

起跳时,玩家的垂直速度被设置为 0.42。在接下来的每一刻都会减少 0.08(重力),然后乘以 0.98(阻力)。

  • 当玩家顶到天花板时,其垂直速度被设置为0,并立即开始下落。
  • 当玩家碰到地面时,他们的垂直速度被设置为0,并且 onGround 判断条件被设置为 true。
  • 水或熔岩中跳跃使玩家向上移动。


跳跃高度

在 1.9 之前,最大的跳跃高度为 1.249b。在 1.9 以上的版本中,它增加了约 0.003b,使玩家能够跳到 1.252b 高。

在平地上,一个跳跃持续 12 。(0.6s)。


速度

当与 疾跑 结合时,跳跃会向玩家的方向增加 0.2 单位的加速度。

在空中,玩家加速的速度较慢(只有基本加速值的 20%),但却能保存更多的速度(每刻 91%,而不是54.6%)。

因此,疾跑跳跃是一种非常有效的增加和保存速度的方法。


代码

下面的代码片段是关于如何触发跳跃的。

/* 来自 EntityLivingBase.java,去掉了不相关的代码 */
public void onLivingUpdate()
{
    if (this.jumpTicks > 0)
        --this.jumpTicks;

    if (this.isJumping)
    {
        if (this.isInWater())
            this.handleJumpWater(); //motionY += 0.04

        else if (this.isInLava())
            this.handleJumpLava();  //motionY += 0.04

        else if (this.onGround && this.jumpTicks == 0)
        {
                this.jump();
                this.jumpTicks = 10;
        }
    }

    //松开跳跃键会重置 10 刻的冷却时间。
    else
        this.jumpTicks = 0;
}


/* 来自 EntityLivingBase.java */
protected void jump()
{
    this.motionY = 0.42; //初速度

    //应用跳跃提升
    if (this.isPotionActive(Potion.jump))
        this.motionY += (this.getActivePotionEffect(Potion.jump).getAmplifier() + 1) * 0.1F

    //应用疾跑跳跃提升
    if (this.isSprinting())
    {
        float f = this.rotationYaw * 0.017453292F; //乘以 pi/180 转换为弧度
        this.motionX -= MathHelper.sin(f) * 0.2F;
        this.motionZ += MathHelper.cos(f) * 0.2F;
    }
}