- Home /
Light Raycast
For a voxel game I need to check if sunlight from a directional light hit's dirt blocks, to set them to Dirt Blocks With Grass.
I googled a lot but I found not a good solution. Now my question is if you know a good solution.
Why don't you add one box collider (Trigger) on the light and make it long enough, so it triggers the objects, that it hits?
Hey,
thanks for your answer. Yeah I did it in such a way. I added an empty gameobject with trigger. A Collider on the directional light isn't working in my project.
What kind of scale are we talking here? Any physics-based (raycasting, collision) solution is probably not very scalable, and will slow down to a crawl above a certain number of objects. Is there any way you can heuristically simplify the conditions for grass growth? For example, you could check whether there are any voxels above the current block, and if there are none allow it to become grassy. Another thing you could do would be to track changes in light level- this would save you from having to recheck every block every frame.
Not that big. The empty game object is as big as one biome and as the player moves into another biome, the empty game object will move over it.
I found it very stupid that there is not a easy solution to get if light hits an object, really sad that there isn't any function for that.
@SmattyCore, lighting is only part of the rendering framework, it has nothing to do with the rest of the engine. You must remember that there is no direct way of deter$$anonymous$$ing whether something is being lit up, because things that aren't on screen just don't get lit up.
The only way of overco$$anonymous$$g this is by using workarounds, like in $$anonymous$$ecraft where lighting is calculated on a per-voxel basis and not using shaders :)