How do I make a character take damage?

0 favourites
  • 4 posts
From the Asset Store
This sound pack features 117 game sounds : Axe,Punch Swing & Hit & Damage. This is a perfect collection for your game.
  • The software is great and all, but a lot of times I feel that transferring my ideas from my brain to the C2 project, is like having your wishes granted by an evil genie. Always a horrible twist in them. Maybe this'll be until I get 100% used to how the program works.

    Anyway, my problem today is this, and I hope there's someone kind enough to help me. It's absolutely essential for pretty much any game with a life bar!:

    I have a top-down view perspective in my game.

    And I have this character who moves in 8 directions.

    Now... I want to have a particular terrain type in which if the character STEPS on it, he'll take damage.

    Here's what I've done:

    1.- Added global variety: P1HP (Player 1 Health Points) = 3 (character starts with three "hearts")

    2.- Added a sprite-terrain called DAMAGE, where the character is supposed to walk on and take damage.

    3.- Added Variable: "takingdamage"

    4.- Added Event:

    If P1HP = 0 ||| Then Player 1 = DESTROY

    5.- Added Event:

    IF PLAYER OVERLAPS DAMAGE|

    +"takingdamage" = 0||| Set "takingdamage" = 1

    6.- Added Event:

    IF "takingdamage" = 1 ||| Substract 1 from P1HP

    Player 1 Opacity Set: 20

    Wait 0.2

    Player 1 Opacity Set: 80

    Wait 0.2

    Player 1 Opacity Set: 20

    Wait 0.2

    Player 1 Opacity Set 100

    "takingdamage" Set 0

    ----

    And playing around with this, I've gotten two totally different results:

    A: The player is destroyed the second it touches the DAMAGE field.

    B: The player blinks (opacity), but never gets destroyed.

    I have NO idea why the game acts like it does. And more importantly, why are there specific moments when the program ignores the "WAIT" commands.

    I would REALLY appreciate the help.

  • The reason he's being destroyed is because he's constantly overlapping the DAMAGE sprite, so all those events will keep executing until finally, the player runs out of HP and is destroyed. Add a new condition to the overlap event - SYSTEM -> TRIGGER ONCE WHILE TRUE

    5. IF PLAYER OVERLAPS DAMAGE

    +TRIGGER ONCE WHILE TRUE

    - takingdamage = 0 then takingdamage = 1

    I think I've read your question right. Soz if not, I haven't been to bed in over 40 hours ;p

  • Thanks, I'm looking into it with what you suggested.

    No luck so far because apparently the character is indestructible now. (I think it was destructible before I tried your suggestion). Apparently it's either not substracting a 1 from the HP variable, or it's not triggering DESTROY when the HP variable reaches 0. It's so weird... In theory, this should be a PIECE OF CAKE. But when I try to put it in events, it just won't work! It's a bit frustrating.

    EDIT:

    Finally got it working! It was a lot simpler than I thought.

    _______________________________________________________

    Player 1 Overlapping DAMAGE||

    + System: Trigger Once||||||||| Substract 1 from "HP"

    ---SUB EVENT:

    ---If HP=0 ||| Player 1 Destroy

    _______________________________________________________

    That was it!

    Anyway, your help is MUCH appreciated!

    You now have my permission to go to bed.

    Haha, jk. Thanks again!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Glad you sorted it! Nothing worse than something like that to eat up your time. Thanks for the permission... finally! haha

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