Change mesh size

Is there any other way how to change a mesh’s size than using scale?

Hi iHux3,

Depending on what you’re trying to do, there could be lots of ways, including manipulating the vertices themselves. Can you tell us a little more about your use case?

Thanks for your response. I want to create a simple HP bar (above players), which will change its size depending on current HP from 0% to 100%.

Okay, cool. I’ve most commonly seen that done using scale, usually with something like bar.scale.x = 1.0 for 100% health and ... = 0.0 for 0%. Is there a way we can make that work for your use case?

That works pretty well. I just had some problems with scaling before, but now it works well. Thank you @syntheticmagus

1 Like

Hi guys. Babylon GUI’s imageOnlyButton is a fun GUI control. It is an “impure”… “pure control”. :slight_smile: More on that, later.

https://www.babylonjs-playground.com/#PF5SYT#14

The important thing… it is 2-pieces… a button and an image. So, it’s clickable, AND it has pointer onEnter and onOut (and many more events) event/animation (goes slightly transparent on mouse-over, but u-program-it to do anything), AND you can get a “ref” to its “child” image - line 26.

The image used in this button… is a little red box texture… simple. AND… that image… has a .left setting… to move it left/right inside the button’s rectangle. This allows… “stuff” to happen.

The image/texture .left can be percentage or pixels. The current automated range-tester is running with percentages. Line 33 is an example of how-to manually set it’s percentage value.

Possibly useful, if you don’t mind using BJS GUI system. Study " Tracking positions " to keep it link-to and positioned-near… your moving mesh.

Activate line 54 - button is no longer clickable or pointer-active. Or, activate lines 56-58, and your health-bar-button has a click-handler/action.

Just another option for chewy-gui health bars. :slight_smile:

Note: When using a larger .thickness setting on the button, we can see that this technique… seems to make the right-side border… struggle to stay displayed. I’m not sure what causes that, yet. Thinkin’.

1 Like

Hello iHux3,

I implemented a cool easy HP bar once without scaling.

The texture of the bar was a gradient from green to red. At first the bar is all green but as the player loses hitpoints, I just used the texture offset to move more red into the bar.

You could also use two solid colors with the distinct line changing from green to red. Worked really well.

Just a thought. The red was easier to see out of the corner of your eye.

Happy coding,
Skrapps

1 Like