Search Unity

Tree collision

Discussion in 'Scripting' started by ohm, Aug 2, 2009.

  1. ohm

    ohm

    Joined:
    Aug 24, 2008
    Posts:
    88
    Hi,

    I can't get the tree collision to work. I'm using a player controller and the move function and collision is working fine against static meshes and against some capsules that I'm using. But even if we can see the tree colliders (capsules) in the prefab it won't work when in game. Any ideas?


    //ohm
     
  2. carbonization

    carbonization

    Joined:
    Mar 23, 2009
    Posts:
    37
    Select your terrain and make sure that "Create tree colliders" is checked in the properties tab.
     
  3. EmadGh

    EmadGh

    Joined:
    Jun 10, 2009
    Posts:
    147
    You must put your tree in a new prefab and make a collider for it.I think capsule collider is use full for this.
     
  4. ohm

    ohm

    Joined:
    Aug 24, 2008
    Posts:
    88
    The "Create Tree Colliders" checkbox is checked. We are loading the terrain from script with code locking something like this:
    Code (csharp):
    1.  
    2. TerrainData terrainData = (TerrainData)Resources.Load(path, typeof(TerrainData));
    3. GameObject terrain = Terrain.CreateTerrainGameObject(terrainData);
    4.  
    Would that matter?


    //ohm
     
  5. ohm

    ohm

    Joined:
    Aug 24, 2008
    Posts:
    88
    This is how we are doing:

    1. Create new prefab
    2. Setup mesh, materials and stuff
    3. Add capsule collider
    4. Use as a tree in the terrain editor

    What have I missed? Should I make one prefab with just the mesh and then another based on that one with a collider?


    //ohm
     
  6. EmadGh

    EmadGh

    Joined:
    Jun 10, 2009
    Posts:
    147
    that's right.
     
  7. muso56

    muso56

    Joined:
    Jun 24, 2008
    Posts:
    12
    we discovered if you programatically alter the location of the terrain the tree colliders no longer work.. if the trees were created when the terrain was at 0,0,0 and the terrain remains at 0,0,0 they work otherwise you have to move the terrain THEN create the trees. Moving the terrain after the trees are created will turn off the colliders (perhaps they retain their original location ..i dunno)