Search Unity

Sharing simple LOD script

Discussion in 'Made With Unity' started by Westmark, Aug 24, 2011.

  1. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
    Hi all :)

    Just wanted to share a simple LOD script I have made.
    I did a search for one earlier and could find one that fitted my requirements, so decided to make one myself.
    It is fairly optimized and should be idiot proof :p

    Anyway here it is :) hope someone will find it useful.

    Documentation is in the file :)
     

    Attached Files:

    • $Lod.js
      File size:
      2.4 KB
      Views:
      2,128
  2. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    Before I read the actual commentary in the script, I had no clue what LOD stood for. :p

    But actually it seems quite useful! Thanks!

    But, and excuse me, what do lod1, lod2, and lod3 do?
     
  3. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
    lod0 is max detail, lod2 is min detail. you need to put a lower detailed mesh in lod1 and lod2 (fewer polygons) :)
     
  4. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    Oh, so like a sample object for how many polys all the others get?

    And does this work for automatic leveling? (not dragging and dropping every single gameobject into a variable?)
     
  5. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
    nope no automatic stuff. I suggest you use prefabs with the script and lower level objects already attached. see attachment:

    EDIT: ohh I see I forgot to mention that you need to tag your player with a tag named "Player"
     

    Attached Files:

    • $Lod.jpg
      $Lod.jpg
      File size:
      152.8 KB
      Views:
      2,276
    Last edited: Aug 24, 2011
  6. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    OOOOHHHHH!

    Now I get it! Thanks a lot! :D
     
  7. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
    No problem :D
     
  8. wkmccoy

    wkmccoy

    Joined:
    Jul 6, 2010
    Posts:
    29
    This is interesting, I was messing with many variations of this as well. Does your script assume the LOD1 and LOD2 are already on the stage in the spot they need to be in. (meaning placed in the scene) ??
     
  9. Kokumo

    Kokumo

    Joined:
    Jul 23, 2010
    Posts:
    416
    As far as i can see, i could say: yes it does.
    The only thing the script does, is to enable/disable the lods depending on the distance and, of course, its existence.

    The script could be more generic and iterate through the children of the object where the script is attached to... but i guess 3 levels of lod are fine enough.

    Thanks Westmark!
     
  10. delibowlen

    delibowlen

    Joined:
    Jan 16, 2013
    Posts:
    57
    Nice script, very useful to me... Many Thanks dude ;)
     
  11. abdoo47

    abdoo47

    Joined:
    Feb 16, 2013
    Posts:
    1
    Thank You, very useful :)

    i converted the script to C# and modified it to use less CPU

    The modified script is attached.
     

    Attached Files:

    • $LOD.cs
      File size:
      2.1 KB
      Views:
      1,515
    Last edited: May 23, 2014
    KingLlama likes this.
  12. Meceka

    Meceka

    Joined:
    Dec 23, 2013
    Posts:
    423
    Thanks for sharing this.
     
  13. KingLlama

    KingLlama

    Joined:
    Jul 18, 2015
    Posts:
    199
    You're a god send.......