Version: 5.6 (switch to 2017.1b)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Terrain.SampleHeight

public float SampleHeight(Vector3 worldPosition);

Description

Samples the height at the given position defined in world space, relative to the terrain space.

void LateUpdate()
{
    Vector3 pos = transform.position;
    pos.y = Terrain.activeTerrain.SampleHeight(transform.position);
    transform.position = pos;
}