Search Unity

Actual Height from Perlin Noise

Discussion in 'Physics' started by 12domb18, Jan 15, 2020.

  1. 12domb18

    12domb18

    Joined:
    Nov 13, 2018
    Posts:
    6
    I've been trying to find the height of a certain spot on a terrain. On this terrian I used perlin noise to make the terrain more dynamic with its heights so that there are plenty of hills and valleys. In this terrain, I cut out a hole. In this hole, I want the player to be able to "fall into it" but not actually have to drop the whole distance. I want a little hit area near the top of the hole so that way when the user falls in, they only fall for a small distance before the death screen comes up, not the entire depth of the hole. The problem is my calculation to find the top of the hole aren't correct.

    Attempts

    I tried two things:

    1.) Terrain.activeTerrian.SampleHeight(x,y)

    This one produces weird and inconsistent results. I don't know how to make a method to the madness. Sometimes the height of the hitArea is well above the top of the hole and other times it is well below. I can't seem to find why.

    2.) terrianData.GetHeight(x,y);
    This one consistantly produces 0. I don't know why, that's all I get.

    What is the best way to find the actual x,y,z location for a certain point on a terrain? Am I doing one of the two attempts above incorrectly?