How do I make a heath bar that locked on the right side and decrease from left side?

I found out a video talking about health bar:
Which technically just construct the X value to the centre.
But it could only works when it locked on the left side and decrease from right side.
Then how do I make a heath bar that locked on the right side and decrease from left side?

Comments

  • Spalding004Spalding004 Member, BASIC Posts: 89
    edited December 2015

    Typically the way you would make a health bar like that would be to constrain its X position to

    (where you want it centered)-(the width of the bar)*(1/2)

    Or, you can make it easy on yourself and use a replicate behavior on a small actor like this:

    number of copies: (health attribute)
    replicate direction: left

    so when you have full health, the the bar is a certain length and as health decreases it dynamically shrinks.

    Or, if you wanted the bar to only be a certain length, under # of copies you could use this expression:

    (current health of character/full health of character)*(max width you want for the bar)

    which would result in a health bar of whatever length you wanted.

    I'm assuming here a 1px wide actor. If you wanted a thicker actor for whatever reason you'd need to adjust the expression a bit.

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    I have a drop dead simple health bar tutorial below. It uses the Replicate Behavior so you can change the direction really easily.

  • OrvilFoxOrvilFox Member Posts: 67

    @jamie_c said:
    I have a drop dead simple health bar tutorial below. It uses the Replicate Behavior so you can change the direction really easily.

    I see. But is this way you provided has a lack of performance? Replicate in 1 pixel sounds..A lot of works to do for the engine.

  • OrvilFoxOrvilFox Member Posts: 67

    @Spalding004 said:
    Typically the way you would make a health bar like that would be to constrain its X position to

    (where you want it centered)-(the width of the bar)*(1/2)

    Or, you can make it easy on yourself and use a replicate behavior on a small actor like this:

    number of copies: (health attribute)
    replicate direction: left

    so when you have full health, the the bar is a certain length and as health decreases it dynamically shrinks.

    Or, if you wanted the bar to only be a certain length, under # of copies you could use this expression:

    (current health of character/full health of character)*(max width you want for the bar)

    which would result in a health bar of whatever length you wanted.

    I'm assuming here a 1px wide actor. If you wanted a thicker actor for whatever reason you'd need to adjust the expression a bit.

    I see..But I guess using this method will be adjusted by the device resolution? Some device might have 1000 pixel but some might have 5000... will this still work?

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    Replicate works super fast, I wouldn't worry about any kind of performace hit. Its easy enough to incorporate, try it out and see.

  • MentalDonkeyGamesMentalDonkeyGames Member Posts: 1,276

    Replicate is super light on the engine.

    Mental Donkey Games
    Website - Facebook - Twitter

Sign In or Register to comment.