Hi,
Here’s the deal. I have a ship. That ship has shields. The shield shader has a falloff option so effect can disappear as the falloff increases. I’m trying to figure out the math so that as the shields take more damage the shaders falloff goes up and the shields appear to be failing. The problem I’m running into is that the falloff is the opposite of the shield percentage. If the shields have a 0% the falloff should be at 15, while a shield value of 100% would be a shader falloff value of 2 showing pretty much all the shields. I think I would use Mathf.Clamp but again I don’t know.
Any help on this would be appreciated
Not sure I understood you, and you probably won’t understand me but think maybe about something like (1 - X) formula no ?
Sorry if I’m not relevant :s
so the percentage only effects 13 units of the 15 , so if the shield is at 7.69% the value should be 14. yes? 15.38 % is 13 and so on.
so for every 7.69% you take one from 15,
so
YourSheild / 7.69f + 2.0f = falloff
see if that works
//percent is float between 0f and 100f
var fadeoff = 15 - (percent/100*13);
getamac, thanks for the reply.
rokstar234,NPSF300 it looks like both of those work, at least on paper. Once I get home tonight first thing I plan to do is plug each into the code to make sure. I will probably go with NPSF3000’s because if I change the shader code and different values will work for the shields on and off it’s easy to change the “15” and “13” value’s vs figuring out the percent and changing the code. In either case thanks for the help guys.
Russ
You can also try this:
shaderFadeoff = Mathf.Lerp(15f, 2f, Mathf.InverseLerp(0f, 100f, shieldPercentage));
The Mathf class already has it all figured out 
Although for a value that ranges from 0 to anything, you don’t have to use Mathf.InverseLerp… you can just divide the current value by the max value.
Mathf.InverseLerp is useful for when you want to convert any range into a 0-1 scalar.
Cheers
Thanks HarvesteR, It almost worked, I think if I played with it a bit I could get it easy, but NPSF3000’s worked when I plugged it in. The only thing I had to do was take out the “/100” being the code snippet it was reading was already in decimal form.
var fadeoff = 7 - (percent*5);
worked like a charm. And upon playing with it I changed the 15 2 to 7 and 2 which just looked better.
Thanks for the help guys. I love how there are multiple ways to do everything.