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

Get help using Construct 2

Post » 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.
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » 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
B
24
S
4
G
2
Posts: 41
Reputation: 1,543

Post » Wed Mar 19, 2014 8:07 am

Plonk
Last edited by shirokuma on Thu Mar 20, 2014 12:43 am, edited 1 time in total.
B
17
S
4
G
3
Posts: 172
Reputation: 1,933

Post » 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!
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » 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.
B
24
S
4
G
2
Posts: 41
Reputation: 1,543

Post » 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
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » 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. :D
B
24
S
4
G
2
Posts: 41
Reputation: 1,543

Post » 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. :D


Me too :D
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?
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » Wed Mar 19, 2014 9:30 am

kossglobal wrote:Me too :D
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.
B
24
S
4
G
2
Posts: 41
Reputation: 1,543

Post » Wed Mar 19, 2014 12:52 pm

For you here
You do not have the required permissions to view the files attached to this post.
B
17
S
7
Posts: 360
Reputation: 2,202

Next

Return to How do I....?

Who is online

Users browsing this forum: jasontoups, raptor0555 and 1 guest