【问题标题】:How to combine Phaser 3 gravity and drag?如何结合 Phaser 3 重力和阻力?
【发布时间】:2019-04-18 21:11:55
【问题描述】:

我需要一个 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)
    }

【问题讨论】:

    标签: javascript phaser-framework


    【解决方案1】:

    您的阻力数字似乎太小了。在 0.95 和 60fps 时,我认为您将在 0.5 秒内完全停止。尝试 0.99 或 0.999 并从那里开始。

    【讨论】:

    • 但问题是它禁用了重力效果。角色只是非常缓慢地向下移动,但不像重力作用时那样加速。
    • 我敢肯定,如果阻力太大,会看起来像没有重力。更改数字不起作用吗?此外,阻尼和阻力的工作方式彼此不同。你可能想要allowDrag=true,但useDamping=false。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    相关资源
    最近更新 更多