0 Favourites

(platformer) destroy blocks when the player walks on them

  • Hi.

    I'm trying to achieve a well known effect in platformer games where cracked blocks are destroyed when the player walks on them.

    A destructible block should be destroyed only if :

    The entire player hitbox touches it, OR any part of the player hitbox touches it as long as the remaining hitbox touches another destructible block.

    If the player keeps running on a bridge made of destructible blocks, they should be destroyed one after the other as the player run over them (like with a 0.5s delay).

    Any idea how to achieve this ?

    The last picture represents what would happen if the player spawns directly on the center destructible block and if its hitbox is smaller.

  • I'd add a timer-behaviour and then something like this should work..

    player is overlapping at offset y=2 destructible

    destructible set timer "destruct" for 0.5

    destructible on timer "destruct

    destructible destroy

    You might be able to do this with just a wait action, because you want to destruct anyway..

  • I already tried this but it doesn't work for the two first pictures I posted : if the player is overlapping at y=1 a cracked block BUT also overlapping at y=1 an indestructible block, then the destructible block shouldn't be destroyed.

  • Add another condition?

    Player is not overlapping at offset other block..

  • Okay I managed to make it working with this :

    There is still one issue thought. If the player is still, overlaps both an indestructible and a destructible block and his width suddently decreases, making him overlapping only the destrutible block, it doesn't trigger the condition and the destructible block is not destroyed. I guess I should put these conditions in a function I call at each tick but also each time the player width changes…?

    edit : forgot to link the picture

  • The event should work, even with the width decreasing..

    Not sure how you have your event set up though..

  • Well I used a function which is called at each tick and when the player width changes and it works perfectly. \o/

  • Here's one way to do it:

    To satisfy the requirements of the first two images you need to only let the blocks fall if all of them are destructible. The logic looks like this:

    global number cnt=0
    
    +---------------------------------------+
    | player overlaps block at offset (0,2) | set cnt to block.pickedCount
    +---------------------------------------+
        +-----------------------------------+
        | block is destructable             | let block fall
        | cnt = block.pickedCount           |
        +-----------------------------------+[/code:21xe7lsc]
    
    The block delay bit can be done with by queuing the blocks to fall up and letting them fall one by one.
  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Thank you very much

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)