在 2D 汽車遊戲中模擬下壓力 (Simulate Downforce in a 2D Car Game)


問題描述

在 2D 汽車遊戲中模擬下壓力 (Simulate Downforce in a 2D Car Game)

我正在嘗試為 2d 汽車遊戲添加下壓力,以給人一種“在軌道上”的感覺。但我在掙扎。我使用 box2d 作為物理引擎,我可以創建一輛有點像小行星遊戲中的船移動的汽車,但我不確定我需要添加哪些額外的力量以及在哪裡(以及何時)添加它們?目前,當我加速時我正在施加一個向前的力,當我轉彎時我將汽車旋轉一個角度。

那麼,如果你以下面的小行星克隆為例,我將如何模擬下壓力效應?或者甚至在“在軌”之間進行調整。和“在冰上”?

https://piqnt.com/planck。 js/小行星

我已經嘗試為像下面這樣的簡單 cos/sin 數學放棄 box2d,這確實得到了我想要的效果,但我希望使用 box2d 來增加更多的可控性。另外,我想調整下壓力的水平:

this.velocity.x += Math.cos(this.angle.rad()) * this.acceleration;
this.velocity.y += Math.sin(this.angle.rad()) * this.acceleration;
this.position.add(this.velocity);

任何幫助或指導將不勝感激。非常感謝,J。


參考解法

方法 1:

Well, after about a month of searching! I found the answer in this video (at the 32min mark): https://youtu.be/0Quv9U9_a8c

As I suspected, it was a rather simple fix. I needed to remove the sideways velocity using dot product. The guy in the video explains it much better than me and also demonstrates exactly what i'm looking for.

As a bonus for me he also demonstrates tweaking the slide from full grip ("on rails") to really slippery ("on ice").

(by JayieJayie)

參考文件

  1. Simulate Downforce in a 2D Car Game (CC BY‑SA 2.5/3.0/4.0)

#game-physics #javascript #2d






相關問題

Android AndEngine:簡單的精靈碰撞 (Android AndEngine: Simple sprite collision)

Box2D - 收集硬幣 (Box2D - collect a coin)

LibGDX - 只有可拖動的運動 (LibGDX - only draggable movement)

Swift 2 中的遊戲 - “touchesBegan”? (Game in Swift 2 - "touchesBegan"?)

SKCameraNode 跟不上移動節點 (SKCameraNode doesn't keep up with moving node)

2D 平台遊戲:為什麼讓物理依賴於幀率? (2D platformers: why make the physics dependent on the framerate?)

基於脈衝的物理 - 在輕物體上堆疊重物體 (Impulse based physics - Stacking heavy object on light object)

建造一堵提高速度統一的牆 (Make a wall that boost speed unity)

Unity Golf 遊戲物理和運動控制器 (Unity Golf game physics and movement controller)

在 2D 汽車遊戲中模擬下壓力 (Simulate Downforce in a 2D Car Game)

向前和橫向球員運動 (Forward and Sideways Player movement)

如何在 Unity 中進行沒有物理的碰撞檢測? (How to have collision detection without physics in Unity?)







留言討論