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


問題描述

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

I'm fairly new to Box2D and I'm trying to make a simple game where a character jumps and picks a coin. I was able to create a contact listener and delete the coin when the contact was detected. The problem is that character and coin collided. I was able to filter out their contact but than I'm not able to determine if the character hitted the coin. I'm sure that there must be some relatively easy way to do it since there are collectible items in almost every game, but I just didn't find the way to achieve that.

Thanks for answer.

‑‑‑‑‑

參考解法

方法 1:

You are right, there is such way. Simply set isSensor to true in b2FixtureDef of the coins. It will disable the coin interation with the physic bodies, but contacts will continue creating.

More info about sensors in Box2D you can find there.

(by adamPavel)

參考文件

  1. Box2D ‑ collect a coin (CC BY‑SA 3.0/4.0)

#box2d #game-physics #box2dweb






相關問題

nodejs服務端模擬 (nodejs server-side simulation)

我們在 JBox2d 中有 RopeJoint 嗎? (Do we have a RopeJoint in JBox2d?)

如何檢查可變數組中是否存在 b2Body? (How to check if a b2Body exists in a Mutable Array?)

通過窗口調整大小改變世界邊界 (Change world boundaries with window resize)

摩天輪式結構b2revolutejoint (Ferris wheel type structure b2revolutejoint)

使啟動遊戲中的物理體旋轉更少,更逼真 (Make physics body in launch game less rotating and more realistic)

實體未插入解析樹 (Bodies not being inserted in resolution tree)

將 NSValue 解碼為 b2fixture 時的 EXC_BAD_ACCESS (EXC_BAD_ACCESS when decoding NSValue into b2fixture)

Box2dFlash - 如何預測碰撞? (Box2dFlash - How to predict a collison?)

Flash Box2D 沒有檢測到碰撞? (Flash Box2D not detecting collisions?)

在 Box2d UserData 中保存 NSObject 的子類並將其取回? (Saving a subclass of NSObject in Box2d UserData and retrieve it back?)

Box2D動態體掉屏 (Box2D dynamic body falling off screen)







留言討論