Search Unity

How to make an object rise through terrain, and continue to walk on it?

Discussion in 'Scripting' started by wpeay, Mar 12, 2018.

  1. wpeay

    wpeay

    Joined:
    Aug 10, 2017
    Posts:
    8
    I have objects in the form of ants, and I want them to be able to rise out of the terrain and begin their waypoint navigation. I already have the waypoint/navigation system working. There's a Nav Mesh on the terrain as well. I'm trying to make it look like the ants are coming out of an ant hill. I know how to make objects rise, but don't know how to engage them to walk on the terrain after rising up
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Will they be walking with the navmesh agent? Maybe get them to rise up (disable any components that might prevent that, if applicable). During the rise, check that they're above the terrain height, and then set their destination?

    That sounds right to me.. just thinking out loud.
     
    SparrowGS likes this.
  3. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    My thoughts too, disable collider and navAgent, while rising raycast down, when you detect the ground enable them and your good to go.
     
  4. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    If your terrain is flat checking the transform.position.y vs ground level is way less expensive than raycasting, but if its not flat it ain't gonna work.

    You can make the raycast solution better by doing a single raycast from the sky down(with the same x and z) as the corresponding ant to get its ground level and lerp the ant there
     
  5. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    You can check against the sample height of the terrain, too as another option.
     
    SparrowGS likes this.