Search Unity

Quick question about GetHeight() and GetSteepness()

Discussion in 'Editor & General Support' started by Maker16, Jul 19, 2011.

  1. Maker16

    Maker16

    Joined:
    Mar 4, 2009
    Posts:
    779
    I discovered these function on TerrainData, but not sure If I was trying to use them right. Firstly, dose GetHeight take the actual terrain position, the heigtmap position, or does it want a value from 0 to 1? It was doing some wierd stuff, locking up on the same number over and over again, but then it occurred to me this morning that maybe, because my terrain is larger than the heightmap, it is "locking up" on the same number because the world position I was feeding it was larger than the heightmap. That would also explain why my values seemed wacky.

    On GetSteepness() (why, oh why, not GetGrade()), same question about the arguments passed in, but, also, what will the returned value represent? I haven't gotten that to work right yet (probably for the same reason as above), but does it return the actual slope of the terrain in degrees?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There are only x and y arguments for GetHeight, and they are ints, which means it can't be world position, it can only be heightmap position. Maybe you'd prefer to use Terrain.SampleHeight. GetSteepness uses x and y, but they are floats, which means it uses the normalized heightmap position (might be nice if it used the same coords as GetHeight, but whatever). The return value is 0 for flat terrain, and 90 for a sheer cliff (which isn't quite achievable with a heightmap, of course).

    --Eric
     
  3. Maker16

    Maker16

    Joined:
    Mar 4, 2009
    Posts:
    779
    Thanks, Eric.