Search Unity

Need hints about colliders for my chunked LOD Terrain System.

Discussion in 'Physics' started by le_duke, Jan 26, 2016.

  1. le_duke

    le_duke

    Joined:
    Aug 30, 2011
    Posts:
    48
    Hi guys,

    I'm thinking about the possibility to use a custom terrain system based on chunked LOD for my paragliding simulator.
    The goal is to have a terrain system that fit my need in a better way than the Unity terrain system does.
    (I would like to have large draw distance, an easy workflow to pre-process real world data, the ability to stream terrain data...)

    I've worked on a prototype and it's currently working pretty well for rendering.
    But I'm getting in trouble when I want to give my chunks the ability to collide with other gameobjects.

    Each of my chunks are meshs of 64*64 vertices on wich I modify Y position of each vertices using an heightmap.
    My first approach was to add a mesh collider on the chunks near the player because it's where I'll need collisions.

    I'm using this line of code to add the collider :
    Code (CSharp):
    1. gameObject.AddComponent<MeshCollider>();
    The problem is that if I do that even on only one chunk of terrain I get an huge spike on the cpu when the collider is added.

    So i'm looking for alternative solutions to handle the collisions.

    The unity terrain system is using a collider named Terrain collider do you know how does it work ?
    I think it is using directly the heightmap data of the terrain but could I do something similar to this for my terrain system ?

    Do you know any efficient way i could use to handle collisions ?

    I've made some search about other terrain engines in Unity but I find only voxels terrain systems.
    Do you know how those type of terrain systems handles colliders ?

    Thank you for your help !
     
  2. Iron-Warrior

    Iron-Warrior

    Joined:
    Nov 3, 2009
    Posts:
    838
    What kind of collisions do you need? Do you just need to know when the player collides with the terrain? If all you want to do is detect intersections, you could just write a custom method to test intersections between the terrain and your player (a capsule?). This isn't too complex and can be done pretty fast, since for a heightmap you can narrow down what triangle you would be colliding with by checking what triangles you are currently above.
     
  3. le_duke

    le_duke

    Joined:
    Aug 30, 2011
    Posts:
    48
    I would like my player and the paraglider (currently a box collider for the pilot and some box colliders for the wing) to be able to collide with the terrain like it's possible to do with a standard Unity terrain.
    Would be cool if I can use raycasts on terrain too.

    Unity_2016-01-27_16-36-50.png

    The Unity terrain collider is maybe using a method that is similar to what you said ?

    Edit :
    I ended up using meshcolliders because it was the easiest solution to use.
    But instead of adding and huge collider per tile I instantiate multiple smaller colliders over several frames to avoid having too much spikes.
     
    Last edited: Feb 5, 2016