How do I only hit one object?

0 favourites
  • 6 posts
From the Asset Store
12 unique hits, slashes and spells in transparent PNG sequences
  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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

    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:

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

    Thanks

  • 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

  • Ah, thanks, didn't think of it like that.

    Will give it a go, thanks for taking the time.

  • MarkThomas most welcome we are here to help if we can

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