[英]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.