Current list of collision system posts:
Collision System Part 3B: Interactions againThis is a follow up to
part 3A of the collision system series of devlog posts. I said I'd go over how the interactions work in various different hitting-block situations.
The previous post showed Leilani using INTERACTION_BUMP_STRONG to break a block. The interaction that's used varies depending on Leilani's current powerup / state, resulting in differing her ability to break blocks.
- Small Leilani - INTERACTION_BUMP_WEAK
- Big Leilani - INTERACTION_BUMP_STRONG
- Fire Leilani (while in fireball state) - INTERACTION_BUMP_SUPER_STRONG
The main thing Leilani needs to know when hitting a block is whether to rebound off it or not. This is done based on the reaction that the block returns. There are four possible reactions:
- REACTION_BUMP_BUMPED_REBOUND - Block was bumped, whatever bumped it should rebound off it
- REACTION_BUMP_BUMPED_NO_REBOUND - Block was bumped, but don't rebound off it
- REACTION_BUMP_NO_EFFECT_REBOUND - Block was not affected, but still rebound off it
- REACTION_BUMP_NO_EFFECT_NO_REBOUND - Block was not affected, don't rebound off it
I don't quite remember why the difference between BUMPED or NO_EFFECT is important, I don't see any parts of the code that differentiate between these reactions
. So all we need to worry about really is whether it's a REBOUND or NO_REBOUND reaction.
The rest of the effect of hitting the block (whether it gets destroyed, items come out of the block, etc) is all handled in the block's code.
Small breakable block- INTERACTION_BUMP_WEAK: Block is damaged/breaks. REBOUND
- INTERACTION_BUMP_STRONG: Block is damaged/breaks. REBOUND
- INTERACTION_BUMP_SUPER_STRONG: Block immediately breaks. NO_REBOUND
Big breakable block- INTERACTION_BUMP_WEAK: Block is not damaged, only bumped. REBOUND
- INTERACTION_BUMP_STRONG: Block is damaged/breaks. REBOUND
- INTERACTION_BUMP_SUPER_STRONG: Block immediately breaks. NO_REBOUND
Lava rock block- INTERACTION_BUMP_WEAK: No effect on block. NO_REBOUND
- INTERACTION_BUMP_STRONG: No effect on block. NO_REBOUND
- INTERACTION_BUMP_SUPER_STRONG: Block immediately breaks. NO_REBOUND
You can see that NO_REBOUND allows two quite different cases depending on if the block remains intact (in which case it'll behave like any normal solid collision - in the gif above Leilani rolls up and over the block which is normal behaviour when hitting any kind of wall), or if the block is destroyed (in which case Leilani won't respond to the collision at all and will move right through it).
Digging InteractionsOne last block type with quite different interactions altogether is the diggable soil blocks:
This looks like quite a complex interaction between Leilani and the soil block that would require them to be pretty aware of each other's state. But actually they can be fairly well decoupled.
After hitting something solid, and after Leilani has already tried doing the relevant INTERACTION_BUMP_* interactions with no effect, she'll then test to see if something diggable is there. This is done using either INTERACTION_DIG_TEST_WEAK (for small Leilani) or INTERACTION_DIG_TEST_STRONG (for other powerups). These interactions have no actual effect on the block but are intended just for checking whether digging can happen.
The soil block receives this interaction. If it can be dug then it returns REACTION_DIG_BEING_DUG. Otherwise it'll return REACTION_NONE. The large soil block can't be dug by only WEAK digging so would return REACTION_NONE if small Leilani tried to dig it.
After the successful dig test Leilani goes into a dig state in which she'll stick to the wall and keep rolling. She knows which entity she's digging and will adjust her vertical position to match the Y position of the centre of that entity (you can see this in action in the gif above when Leilani digs through the big soil block and lifts off the floor slightly).
Every frame while Leilani is digging she'll continue to collide against the soil block entity and will send another interaction - INTERACTION_DIG_WEAK or INTERACTION_DIG_STRONG (note the lack of "TEST" in these ones). This interaction lets the other entity know that digging is continuing.
When the soil block receives these interactions it goes into its own 'being dug' state, losing integrity over time, emitting particles, shaking, etc. It returns REACTION_DIG_BEING_DUG again which lets Leilani know that she can remain in the digging state.
If Leilani stops digging then the block will just exit from its 'being dug' state because it's no longer receiving the INTERACTION_DIG* interactions. If the block is destroyed then Leilani will no longer collide with it and naturally leave her digging state that way.
Also a quick reminder that these systems aren't specific to Leilani even though I may talk about them as if they are. Some enemies recently gained the ability to dig through soil blocks using the same interactions: