How do I relate the % of missing health to my life's bar

0 favourites
From the Asset Store
Safaryx
$3.50 USD
30% off
The game ends when the player loses all their lives
  • how do I set the width of my life's bar depending of the variable?Because it would be different values. Imagine using a potion that increases your maximum life. That's why I'm trying to get the % of my life.

    So, for an example: If I have 375 of maximum health and I take a hit that took 180 of health, I would have 195 yet. I want to take the % of life that I still have and set the width of the bar.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • For example if your original bar's width is 400 pixels.

    set bar width to 400 * current health / max health[/code:3rm3wd17]
  • Plonk

  • feyninja

    And is there a way to make it runs until it reach the width instead of changing from 100% to 50%, for an exemplo?

    Thanks, man!

    shirokuma

    I'll test it too.

    Thanks man!

  • feyninja

    And is there a way to make it runs until it reach the width instead of changing from 100% to 50%, for an exemplo?

    everytick -> 
    set bar width to lerp(bar width,(original bar width * current health / max health),8*dt)[/code:3leylobp]
    If you don't know what lerp and 8*dt mean, you can search "lerp" and "delta-time" on the manual, basically you can reduce the speed by half by changing it to 4*dt.
  • > feyninja

    >

    > And is there a way to make it runs until it reach the width instead of changing from 100% to 50%, for an exemplo?

    >

    >

    everytick -> 
    set bar width to lerp(bar width,(original bar width * current health / max health),8*dt)[/code:2hs3b24l]
    If you don't know what lerp and 8*dt mean, you can search "lerp" and "delta-time" on the manual, basically you can reduce the speed by half by changing it to 4*dt.
    

    It's not working =/

    It still change without run smoothly

    look:

    lerp(Healthbar.Width,(150*Personagem1.CharacterHealth/Personagem1.MaximumHealth),8*dt)

    I'll study these expressions for sure.

    Edit: My bad, it's working. Thank you very much.

    and oh my god. Lerp is like an Alien to me! My skills are far far far away from math haha

  • https://www.scirra.com/manual/126/system-expressions

    Lerp returned real numbers, so in some case you might want to convert them to integer.

    You must see some expert guys using sin, cos and stuffs for their game, it's driving me crazy. Man i wish that i had put more time on math class. <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy">

  • scirra.com/manual/126/system-expressions

    Lerp returned real numbers, so in some case you might want to convert them to integer.

    You must see some expert guys using sin, cos and stuffs for their game, it's driving me crazy. Man i wish that i had put more time on math class.

    Me too

    At least dt I understand a bit.

    It's important to use dt in every custom movements of objects to prevent lag?

    So If I want to move something 30 degrees, It would be something like this: 180*dt?

  • Me too

    At least dt I understand a bit.

    It's important to use dt in every custom movements of objects to prevent lag?

    So If I want to move something 30 degrees, It would be something like this: 180*dt?

    Yup, if not the lag will break the game.

  • For you here

  • This example might be useful for you. It's a circular life bar example that I made and it shows how to increase/decrease it smoothly and it shows the % too

  • >

    > Me too

    > At least dt I understand a bit.

    >

    > It's important to use dt in every custom movements of objects to prevent lag?

    > So If I want to move something 30 degrees, It would be something like this: 180*dt?

    >

    Yup, if not the lag will break the game.

    Is necessary to use dt when I set vector, since it'snot the object's speed, but a parameter to his platform movement?

    might be useful for you. It's a circular life bar example that I made and it shows how to increase/decrease it smoothly and it shows the % too

    My life's bar is working already but I'll check it out for sure. thanks man.

  • Is necessary to use dt when I set vector, since it'snot the object's speed, but a parameter to his platform movement?

    If the actions come from behaviors you don't need to use dt.

    [quote:2f91x458]Don't forget behaviors already use dt (except with Physics where you must turn it on yourself). If you use behaviors to control all motion in your game, you don't have to worry about dt at all!

  • feyninja

    Ya, I read it in the manual. But the simulate control, where I can set the vector, is a custom behavior, but setting the vector Y -700, for an example, isn't necessary to use dt because I'm not setting movement. Right?

  • Set vector Y action from platform behavior right? I'm not so sure but i think you don't have to worry about dt, because they're a part of the behavior.

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