# Struggling with a math formula

Just started using Construct 2? Post your questions here

### » Sun Apr 20, 2014 1:55 am

edit: I figured it out. It's ceil(currenthealth/maxhealth*28).
I actually had explored this before, but it was with the width of a sprite, rather than the frame number of an animation, so I kinda got confused. sorry if this topic caused any trouble!
B
15
S
2
Posts: 105
Reputation: 1,182

### » Sun Apr 20, 2014 2:19 am

deleted
Last edited by shirokuma on Sun Apr 20, 2014 1:14 pm, edited 1 time in total.
B
17
S
4
G
3
Posts: 172
Reputation: 1,933

### » Sun Apr 20, 2014 2:20 am

So the frame and health ratios are the same so:
Health/maxHealth = frame/28

Solving for frame:
Frame = Health*28/maxHealth

Next we need to round it to a whole number, and since we want frame 0 to be used only if the health is 0 we will use ceil() to round up.

So the formula is:
Frame = ceil(Health*28/maxHealth)
B
95
S
34
G
128
Posts: 5,497
Reputation: 81,682

### » Sun Apr 20, 2014 2:24 am

R0J0hound wrote:So the frame and health ratios are the same so:
Health/maxHealth = frame/28

Solving for frame:
Frame = Health*28/maxHealth

Next we need to round it to a whole number, and since we want frame 0 to be used only if the health is 0 we will use ceil() to round up.

So the formula is:
Frame = ceil(Health*28/maxHealth)

I figured it out on my own, but thanks anyway! It seems like the majority of the people here are nice! That's another newbie problem solved! Wish me luck as I move along with my game, I might post more questions along the way!
B
15
S
2
Posts: 105
Reputation: 1,182

### » Thu May 08, 2014 10:22 am

yes we are here to help if we can
B
262
S
49
G
15
Posts: 2,010
Reputation: 42,237