如何结合Phaser 3的重力和阻力?

时间:2019-04-18 21:11:56

标签: javascript phaser-framework

我需要一个Phaser 3精灵根据重力垂直下落并弹跳。我还希望当玩家释放控制器时身体水平降低速度。

但是似乎重力和摩擦不能很好地协同工作...? 一旦添加阻尼和阻力,重力就会完全拧紧。精灵会掉落得非常缓慢,或者只是完全消除了重力。

如何将水平阻力与垂直重力相结合?

物理设置

    this.body.setBounce(1, 1)
    this.body.allowGravity = true // only works without drag/damping
    this.body.allowDrag = true
    this.body.useDamping = true
    this.body.setDrag(0.88, 0.95) // x drag and y drag

控件

    if (this.cursors.left.isDown) {
        this.body.setVelocityX(-300)
    }
    else if (this.cursors.right.isDown) {
        this.body.setVelocityX(300)
    }

    if (this.cursors.up.isDown) {
        this.body.setVelocityY(-300)
    }

1 个答案:

答案 0 :(得分:0)

似乎您的阻力数可能太小。在0.95和60fps的速度下,我认为您将在0.5秒内完全停止。尝试0.99或0.999,然后从那里开始。