I'm making a game where blocks fall from top to bottom and the player has to climb on them to reach the exit. But if the block lands on top of the player it hurts them. How can I make only the bottom of the block hurt the player and not the top?
It may help to pin an invisible sprite to the bottom of the block. Make sure the edge of the sprite is lined up with the bottom edge of the block. Have it so when on Collision with the Invisible sprite, something happens. Pinning the invisible sprite to the block will let the sprite move with the block.
I would do it exactly like Phoenixbowman says. In my Space shooter linked via my sig I used this several times in lieu of more complex solutions. For example the orb dropper enemies have an invisible sprite pinned way out in front of them that tells them when to drop orb once that sprite overlaps player. If it never does the enemy flies on past off screen still holding orb.
Couple ways to do it:
You can use a blank sprite pinned to your blocks or you can check if blocks collide with ground or another block and then set a variable to turn off the crushing event.
I prefer the variable trigger instead of creating a bunch of extra sprites but whichever works for you.
Maybe it will work by detecting the collision of the sprite to BboxBottom
Develop games in your browser. Powerful, performant & highly capable.
Thanks, that sounds like exactly what I need.
Ok so I got the invisible sprite attached to the falling block sprite. But it only works on the first block that falls. The falling block spawns randomly in 4 different animations. Is that what's causing it not to work or is there something else?
You will need to make sure and pin it to each instance. In the blocks spawn code use an On-created event for each one if different and in it pin the collision block.
This way whenever a block is created it will automatically pin on its collision sprite.
It doesn't seem to work on the On-Created event.
This is the code I have to spawn the blocks
(Sprite-On Created-set animation frame to random)
and to pin it I have.
(System - On start of layout - pin collision sprite to block)
In order to use Pin the object must be newly created... so you either have to do it at start-of-layout or have the blocks spawn the collision sprite and then Pin it.
Each time a block is created have it spawn (action when block sprite is object) the collision sprite at position and then next action Pin it to the correct image point.
In order to use Pin the object must be newly created... so you either have to do it at start-of-layout or have the blocks spawn the collision sprite and then Pin it. Each time a block is created have it spawn (action when block sprite is object) the collision sprite at position and then next action Pin it to the correct image point.
That did it! Thank you so much. I had the block spawn the collision sprite at block's BBox Bottom then Pinned it.