- Home /
2d Fog of War - How to do it efficiently?
Hey folks,
I'm currently looking into how to do 2d Fog of War, Terraria style:
http://www.youtube.com/watch?v=448bmzU61uM
My initial implementation looks like this: I have tons of little planes scattered throughout the world. Since I only know how to use triggers if they have a Box Collider as well as a rigidbody assigned to them, that's what I did. Now the code works like:
If SightTrigger enters, set materialColor to X. If sightTrigger exits, set it back to black.
Now, this works, but it's not very efficient and just rapes the performance, since I literally have around 100 gameobjects just there, all with box collider and rigidbodies applied to them.
Is there a clever way of how to do this implementation without any heavy calculation?
Answer by aldonaletto · Jun 13, 2011 at 02:02 PM
A trigger does not need a rigidbody to work, just a collider. Unless you need the rigidbodies for other purposes, remove them - the physics engine must make a lot of calculations for each rigidbody, which certainly impacts performance. Try to remove a few rigidbodies and check if your game still works fine, then remove all of them if they are not really needed.
Your answer
![](https://koobas.hobune.stream/wayback/20220612104017im_/https://answers.unity.com/themes/thub/images/avi.jpg)