Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Terrain height

Discussion in 'Scripting' started by GodOfMagic, Apr 30, 2014.

  1. GodOfMagic

    GodOfMagic

    Joined:
    Mar 25, 2014
    Posts:
    34
    Hi,
    How can I find terrains heigth (y) in the exact location (x, z)?
    My terrain is created with built-in terrain generator.
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  3. GodOfMagic

    GodOfMagic

    Joined:
    Mar 25, 2014
    Posts:
    34
    i searched just Terrain.smth not TerrainData.smth

    Found this: GetHeight(x: int, y: int): float;
    Hope this helps me.
    thanks
     
    Last edited: Apr 30, 2014
  4. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  5. GodOfMagic

    GodOfMagic

    Joined:
    Mar 25, 2014
    Posts:
    34
    y=TerrainData.GetHeight(x,z);
    BCE0020: An instance of type 'UnityEngine.TerrainData' is required to access non static member 'GetHeight'.
    I get this error :(
     
  6. dterbeest

    dterbeest

    Joined:
    Mar 23, 2012
    Posts:
    389
    y=Terrain.activeTerrain.terrainData.GetHeight(x,z);
     
  7. GodOfMagic

    GodOfMagic

    Joined:
    Mar 25, 2014
    Posts:
    34
    transform.position.y = Terrain.activeTerrain.SampleHeight(transform.position);
    This works great.
    Thanks again.

    y=Terrain.activeTerrain.terrainData.GetHeight(x,z) ; works too.
     
    Last edited: Apr 30, 2014