All Questions


André Bianchini
posted to: Coding the Coin

stomp_impulse upon coin pickup

Checked collision layers and my code sometimes now, but for some reason picking up a coin from above triggers a stomp impulse. Tried to compare to the downloadable project, and there's no more "StompDetector"node on the player's scene. I don't get it. When was this node dropped? And how does the interactions with the enemy are still working?
  • Nathan Lovato replied

    Your coin might be on the Enemy layer, rather than a dedicated Coin physics layer. To check that, select the Coin (kinematicbody2d) node in the Coin.tscn scene, and in the inspector, unfold the "Collision" category.

    Regarding the stomp, at the end of this chapter, the enemy should have a StompArea, and the player only one EnemyDetector. Then, the enemy itself is a physics body (kinematic body 2d) while the enemy's stomp area is a physics area. We can use that to detect if the player should die (touched by the enemy, i.e. the physics body) or use the enemy as a bumper (touched the enemy's stomp area).

    There are some caveats to this approach, it won't be as precise as a more complex setup, but we picked it as it's relatively beginner-friendly.

    I hope it helps, tell me if you need anything else.