Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to get a TerrainData heightmap position given a RaycastHit

Discussion in 'Scripting' started by Victoralm, Jul 26, 2020.

  1. Victoralm

    Victoralm

    Joined:
    Dec 31, 2015
    Posts:
    30
    I'm trying to get a specific rectangle from the TerrainData heightmap using 4 RaycastHits. Mine intention is to rise/lower the terrain only in the area of this rectangle.
    The RaycastHit returns me a lot of information (as in the image) but I don't know witch one to use nor how...
    Need some help, please.

     

    Attached Files:

  2. AnthonySharp

    AnthonySharp

    Joined:
    Apr 11, 2017
    Posts:
    88
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,517
    I have a little first person run-around-and-fling-grenades to deform the ground demo in my MakeGeo repository.

    Inside that code is all the stuff you would need to find that entry in the terrain heightmap.

    Look for the
    TerrainDamager
    scene in MakeGeo. MakeGeo is presently hosted at these locations:

    https://bitbucket.org/kurtdekker/makegeo

    https://github.com/kurtdekker/makegeo

    https://gitlab.com/kurtdekker/makegeo

    https://sourceforge.net/p/makegeo
     
  4. Victoralm

    Victoralm

    Joined:
    Dec 31, 2015
    Posts:
    30
    Hi, thanks for the replies!!
    I think I got a good base with this.
    I'll polish it a little bit more before post the code.
    HeightMapRaycatstHit3.jpg
     
    Last edited: Jul 27, 2020