New to shader graph and working through some tutorials. In making a health bar with a border using a rectangle node, I can’t get the border to stay a consistent size as the object scales. I want the border to be about 10% the size of the object itself but it’s looking like this:
In my shader graph, I’ve tried accessing the scale property from the object node and manipulating it in a variety of ways but can’t get the end result I’m looking for. I think the closest I got was splitting out the scale object and dropping it’s values directly into the W and H of the rectangle, but still no dice. Here’s where I last left it. Any ideas?
It looks like it is 10% of each height and width – to make it have a fixed width that is equal for top/bottom and left/right, you will have to set the Rectangle width to 1 - (0.1 * (Object Scale.y / Object Scale.x)) and keep Rectangle height to 0.9. This is assuming the health bar is always horizontal and assuming “consistent size” means the border thickness stays the same size relative to the overall size.
@florianhanke Wow, thanks so much! This works great. I was just coming back to post my own screenshot
I don’t understand why you wouldn’t have to do the same type of computation for the height as well… but for now I’m free to move on to the next thing. Thanks again!
You basically keep one the thickness you want it at (so 0.9), and use the ratio of scale x/y to calculate the ratio of the other to get the same thickness.
I wrote “assuming the health bar is always horizontal”, because if you make it vertical, then 0.9 on the height is too thick and will look goofy (just set width to 0.9 and flip x/y in the calculation for the height to make it work for a vertical health bar).
Anyway, my pleasure!
Is there a way to plug in the sequence (shown above) into both their respective width and height slots and have them scale correctly? Currently, when scaled separately in either or X or Y, the opposing axis’ width or height collapses in