- Home /
Dynamic lights with a raycast
Hey Guys,
I am new here(also new to unity)
Let me first explain what I am working on so you can understand the context of what I am trying to achieve.
What I use: Unity Pro 3.4.2 City Engine Some other external packages.
My game: I am building a whole dynamic city(GTA style). The city will "live" with loads of people who go around their lives(For example: Eat, sleep, word, get fired, etc) This is still being worked on.
For the moment I am working on the GFX of the city itself. I already have the city itself(buildings, streets)a dynamic night/day cycle and a fully dynamic weather system(volumetric clouds) and dynamic shadows of the sun.
At night, I want the city to turn on its (dynamic) streetlights(MAANY LIGHTS), this takes down the performance of the game very very heavily. So what I would like to do is some kind of LOD system where lights turn on when the player gets within the xx radius of a light and turn off when they are outside a certain radius of the player.
Seeing how I want the lights to drop dynamic shadows on objects around the city I do not want it lightmapped.
I hope this will make performance much better.
Can anyone help me achieve this?
PS, Isn't it supposed to be possible to get dynamic shadows with point and spot lights in the latest unity? Somehow they don't. PPS, I am fairly new with unity, so please consider that!
Answer by PuttPutt · Dec 19, 2011 at 10:53 PM
Solved!
By using a custom var to check for the distance between the main camera and the light(s) (linecast) and when the distance is shorter than xx meters, the command:
light.enabled = true;
else
light.enabled = false;
Depending on your rays this could still become very intensive. Try setting up a sphere collider and make it a trigger, then place a script on that collider with a for loop that turns of every script outside of it and enable all the lights inside it.
Your answer
Follow this Question
Related Questions
How to obtain third person accuracy 0 Answers
Seperate switches for individual lights 0 Answers
Unity and Raycasting/collision 1 Answer
Top down LOS/Field of View 0 Answers
gameObject not dynamically scaling via the update method 1 Answer