Basic damage system help

This forum is currently in read-only mode.
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Okay, so I'm just sort of trying to learn the ropes here. Without worrying about graphics or sound whatsoever, I'm trying to put together a rudimentary system for a sort of platform RPG. I've run into a few snags just trying to make the system that damages the player for colliding with a specific object, shows the health bar decreasing as the player gets damaged, and kills the player if health reaches 0. Here's what my event sheet looks like:

    This kind of works, but it has problems:

    1-The health bar refuses to stay in the correct spot when damage is taken. That is, event 1 is supposed to "save" where its farthest left point is, change its width to match the player's HP, and then put its farthest left point in the same spot after the width is changed, but it seems to sort of jump to the right a bit anyway.

    2-The player is supposed to get knocked back a bit by damage. This works fine coming from the left, but coming from the right it's completely broken. The player gets knocked left no matter where he is.

    3-When the player's HP hits zero, the sprite is switched to the death animation, but then the player is fine until he hits the enemy once more. THEN the death animation plays and the player is destroyed. (The destroy is a placeholder for possibly an attempt to load the last save or make a game over menu or something, but that'll come much later).

    Is anyone willing to help me out?

  • Well, I can tell you how to fix number 3. For each frame the player's health is equal to zero it will keep resetting the "Death" animation over and over again which means it never finishes - adding a "Trigger once while true" condition after the health check condition in event 6 should fix that by making the event run once.

    I can't be sure what's wrong in the first two cases - I have no context for what the objects are or how they're set up. If you provide your CAP file I'll be glad to look at it and help you out.

    I'll just mention that setting the X position of HealthBar won't do anything as HealthBar.X and your 'Location' variable are equal without changing.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Okay, I did that for the death animation and it works now. I suspected that was the issue with the health bar but I don't quite know how to fix it...make it update less often, maybe?

    When the camera scrolls and a layer is pulled with it, the current x position of the objects in that layer change, right? Because otherwise I don't need to do the location thing at all.

    Anyway, here's the file I've been working on.

    Thank you for helping me with..probably some obvious questions here.

  • I had some suspicions that your problems were caused by incorrectly placed hot spots and that is indeed the case.

    Your 'PainBox' object has a hot spot that is far right of center, resting in a position such that - given that the X and Y coordinates represent this point - your player's position will always be left of X relative to that object. Centering the hot spot on the 'PainBox' will fix your knock back problems.

    For the health bar, your hot spot is once again out of alignment based on the effect you want. Placing the health bar's hot spot on the left edge of the image will result in the image extending towards the right relative to the hot spot, just as you want.

    As a nifty little trick - which you may already know - while editing hot spots in the image editor, you can use the number pad on your keyboard to quickly position it to the edges/center/corners of your image. So, for example, 4 sets it to the left edge, vertically centered; 5 to the center; etc.

    I hope all of this helps you out. <img src="smileys/smiley4.gif" border="0" align="middle" />

  • Okay, wow. I wasn't entirely sure what hotspots were for--I knew they centered the image for animations, but didn't know they actually defined the location of the object. That clears it right up. Thanks again.

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