繁体   English   中英

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

[英]How to combine Phaser 3 gravity and drag?

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM