Hello,
I had created a Solar Panel simulation, I now output a value of power, this value ranges from anywhere from 5000 - 20000.
I have a bulb I created with a Light source inside to emulate it being on. What is the best way torelate the two so that the more output on the power value, the stronger the intensity of this light source.
Thanks!
Well, these numbers should be fairly convenient to work with. On the absolute simplest level you could subtract 5000 from your power to get a range now between 0 - 15000. Then, if you divide that by 15000, you now have a number between 0-1, which is easier to work with. Alternatively, if your light is never truly off, you can add a minimum intensity later or change your ranges, or whatever you need to do. You could also use various Mathf functions like log or whatever else you need to make the light change from 5000-20000 less linear.
You can multiply this 0 - 1 range by a multiplier to get a higher range… or add a value to get a higher minimum (and max, of course)… do what you need to to convert 5000-20000 to whatever range you need. Play with a light to figure out the minimum and max intensity you need.
public float power; // store your power in here.. whatever makes sense
public Light light; // drag your light reference here, or find it in code if you must
float intensityValue; // this will eventually just be the conversion of your power to an intensity value
public float intensityMultiplier; // this is just how you'd get it from say 0 - 1 to 0 to 8.. 8 is max intensity, btw
void YourLightFunction()
{
intensityValue = Mathf.clamp((power-5000)/15000), 0.0f, 1.0f); // just making sure it's really 0-1.. you might even want to include the multiplier to ensure the new range is 0-8 or whatever.. set in inspector or in code
light.intensity = intensityValue * intensityMultiplier;
}
This would be the simplest way to do it (assuming this works… haven’t tested!), but you may need to also change things like your light range, dynamically. A similar concept should work for that.
Hope this helps… nothing fancy, but it should work, I would think. I’m no scientist, so maybe there’s some math functions that
Thanks for this! I have made a little modification to the Multiplier, but it works! Much appriciated 