How do I only hit one object?

Get help using Construct 2

Post » Sat Nov 26, 2016 8:26 am

Hi,

I have two players, if player 1 hits (on collision) player 2 and that destroys player 2.

But if I want player 2 to hit player 1, then both get destroyed.

I've come up with a way to only get one destroyed (the one I want hit) by using a sprite pinned to player 2, if that sprite gets hit then destroy player 2.

Is there another way to make player 1 hit player 2 and player 2 hit player one, only destroying the one being hit?

Thanks for any advice.
B
10
S
3
Posts: 55
Reputation: 802

Post » Sat Nov 26, 2016 12:16 pm

@MarkThomas

Are you using the same object to create 2 players? So just instances of the same object or different objects? Please post capx files or screenshots of the mentioned code part. Hard to tell whats going on.
B
34
S
9
G
3
Posts: 206
Reputation: 7,851

Post » Sat Nov 26, 2016 1:48 pm

Hi,
Thank you.

It's 2 different sprites as playable players.

Player 1 wants to hit player 2 and if that happens I wanted player 2 to die.

But I also want: if player 2 turn and he bashes player 1, then only player 1 dies. But because each of them have "on collision with" they both die.

Like this: green player 1, red player 2
Image

The work around I've done is to add a blank sprite and place it over the green player, then I pinned the blank sprite over the green player.
So now when the blank sprite is hit (at the exact location of the green sprite) the green sprite is destroyed but not the red one, and now the green can hit the red without dying like this:
Image

Is this the only way to do this? or have I missed something?

Thanks
B
10
S
3
Posts: 55
Reputation: 802

Post » Sat Nov 26, 2016 2:43 pm

set global variable like isPlayeroneAlive=0
set isPlayertwoAlive=0

now set at start set isPlayeroneAlive = 1
isPlayertwoAlive= 1

check if Playerone hit set isPlayeroneAlive = 0
player one destroyed
Playerotwo hit set isPlayertwoAlive = 0
player two destroyed
B
255
S
39
G
15
Posts: 1,982
Reputation: 41,005

Post » Sat Nov 26, 2016 3:00 pm

Ah, thanks, didn't think of it like that.
Will give it a go, thanks for taking the time.
B
10
S
3
Posts: 55
Reputation: 802

Post » Sat Nov 26, 2016 3:49 pm

MarkThomas most welcome we are here to help if we can
B
255
S
39
G
15
Posts: 1,982
Reputation: 41,005


Return to How do I....?

Who is online

Users browsing this forum: Artcadev, kainrazial and 7 guests