Page 1 of 2

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

Posted: Wed Mar 19, 2014 7:33 am
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.

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

Posted: Wed Mar 19, 2014 7:54 am
For example if your original bar's width is 400 pixels.
Code: Select all
`set bar width to 400 * current health / max health`

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

Posted: Wed Mar 19, 2014 8:07 am
Plonk

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

Posted: Wed Mar 19, 2014 8:21 am
@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!

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

Posted: Wed Mar 19, 2014 8:39 am
kossglobal wrote:@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?

Code: Select all
`everytick -> set bar width to lerp(bar width,(original bar width * current health / max health),8*dt)`

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.

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

Posted: Wed Mar 19, 2014 8:53 am
feyninja wrote:
kossglobal wrote:@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?

Code: Select all
`everytick -> set bar width to lerp(bar width,(original bar width * current health / max health),8*dt)`

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

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

Posted: Wed Mar 19, 2014 9:13 am
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.

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

Posted: Wed Mar 19, 2014 9:22 am
feyninja wrote: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.

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?

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

Posted: Wed Mar 19, 2014 9:30 am
kossglobal wrote: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.

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

Posted: Wed Mar 19, 2014 12:52 pm
For you here