- Home /
Ammount of Light received by a GameObject
Hi guys,
I would like to make a kind of solar panel but after searching for an hour, I have no idea how to do that.
Basically, the panel would calculate the amount of energy produced using the amount of light received on it but I don't know how to get that.
Does anyone have an idea ?
Thanks a lot !
If you don't have to account for things blocking the panel, you can fake it by using the distance from the light source, the angle with respect to the light forward and the angle (or dot product) between the light forward and the panel forward.
Thanks for your comment.
I thought about it but i wanted to use blocking objects and multiple light sources, and it will not fit completely my needs
If you really need to have results compliant with visual representation you will need to setup special projection camera to cover the surface of the panel and use Camera.RenderWithShader, while supplying a special shader which will give you light intensity consumed by panel. Then you can statistically process resultant image. Imagine how slow it will be :)
Unless its for some kind of simulation and not game, I would got with Roberts suggestion, and perhaps do a few raycasts to check if something is blocking the light
In fact, it's for a game that will include small building powered by the panel and the player would have to find the best place in the environment to place the panels and get maximum energy production. But the environment would include shadows, night-day cycles, fog or any other effect that could modify the amount of light
Answer by bubzy · Nov 07, 2014 at 11:23 AM
I would cheat, and set up an array of positions(containing whether there is a shadow there) or have some sort of collider attached to a "shadow" object that can come in contact with the panel, also have variables such as
bool isDay = true;
bool isFoggy = false;
float fogPenalty = 0.2f;
float lightBonus = 1.0f;
float lightPenalty = 0.1f;
float energyProduced = 0;
void someKindOfTimerFunction()
{
if(isDay)
{
energyProduced += lightBonus;
}
else if(!isDay)
{
energyProduced += lightPenalty;
}
if(isFoggy)
{
energyProduced -= fogPenalty;
}
}