Search Unity

Heightmap mesh colliders

Discussion in 'Editor & General Support' started by Mindless_Soul, Jul 17, 2006.

  1. Mindless_Soul

    Mindless_Soul

    Joined:
    Feb 1, 2006
    Posts:
    128
    I am using the example project "Procedural" to make heightmaps. How do you attach a mesh collision model to the heightmap? If you hit test, and then attatch a collider to it, it isn't attatched after you return to the editor. I have tried attatching the collider and then making a prefab of the mesh while in test mode, but it never finishes making the prefab.

    Thanks for any help.
     
  2. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Add a Mesh Collider component to the GameObject and put this snippet at the end of the HeightmapGenerator script inside the GenerateHeightmap function.

    Code (csharp):
    1.  
    2. GetComponent(MeshCollider).sharedMesh = mesh;
    3.  
     
  3. Mindless_Soul

    Mindless_Soul

    Joined:
    Feb 1, 2006
    Posts:
    128
    Thanks for the script snippet. It takes like 5 minutes to load the scene, but it works very well (You've got to love the PhysX engine).

    Is there any way to speed up the loading time?
    I scaled the mesh down quite a bit and it didn't seem to help the loading time much (if at all).

    One more question:
    When using heightmaps, is there a maximum size that the map can be? I made a huge heightmap, but it only uses about 20% of the bottom-left corner.

    Thanks for your help.
     
  4. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    The limit for the HeightMap is 65,536 polygons, a 256x256 image (this is a limitation of OpenGL). Richard_B has done some work sewing together a huge terrain using 4 million polygons and you can check out how he's doing it here.