How do I have a falling block hurt the player.

Get help using Construct 2

Post » Tue Mar 28, 2017 1:53 pm

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?
B
4
Posts: 8
Reputation: 216

Post » Tue Mar 28, 2017 3:41 pm

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.
B
20
S
7
G
3
Posts: 302
Reputation: 3,634

Post » Tue Mar 28, 2017 4:24 pm

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.
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
66
S
17
G
8
Posts: 637
Reputation: 9,370

Post » Tue Mar 28, 2017 5:37 pm

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.
Banned User
B
27
S
7
G
58
Posts: 1,229
Reputation: 34,790

Post » Wed Mar 29, 2017 6:58 am

Maybe it will work by detecting the collision of the sprite to BboxBottom
B
36
S
10
G
9
Posts: 212
Reputation: 6,945

Post » Wed Mar 29, 2017 1:59 pm

Phoenixbowman wrote: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.


Thanks, that sounds like exactly what I need.
B
4
Posts: 8
Reputation: 216

Post » Wed Mar 29, 2017 2:27 pm

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?
B
4
Posts: 8
Reputation: 216

Post » Wed Mar 29, 2017 4:42 pm

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.
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
66
S
17
G
8
Posts: 637
Reputation: 9,370

Post » Thu Mar 30, 2017 10:40 am

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)
B
4
Posts: 8
Reputation: 216

Post » Thu Mar 30, 2017 2:48 pm

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.
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
66
S
17
G
8
Posts: 637
Reputation: 9,370

Next

Return to How do I....?

Who is online

Users browsing this forum: datiel12, tarek2 and 59 guests