Search Unity

Question How to obtain the path of a slope

Discussion in 'Navigation' started by tochimochi, Jan 17, 2023.

  1. tochimochi

    tochimochi

    Joined:
    Jan 6, 2023
    Posts:
    19
    Currently, when drawing a path according to the navigation, it penetrates the slope as shown in the first image.
    If the point of the path is at the red circle as shown in the second image, the path can be drawn cleanly.
    Is there any way to do that?
     

    Attached Files:

  2. androvisuals_unity

    androvisuals_unity

    Joined:
    Mar 23, 2020
    Posts:
    47
    You'll need to generate your own positions array.

    I'll use an example of a line between two points to make it simple.
    Get point a and point b positions.
    Get the position between them (just do a vector3 lerp at 0.5 of the two positions)

    Now do a raycast straight down from above that position. Where it hits the floor is where you want to add an extra position to your path array. so you'd have (a, raycastHit position, b)
    You could also have a line and split it into multiple parts all with a raycast down to get the hit location.
    It won't be perfect in all situations but for situations like the one in the pictures it should easily solve it.

    upload_2023-1-19_13-16-8.png
     
    tochimochi likes this.
  3. tochimochi

    tochimochi

    Joined:
    Jan 6, 2023
    Posts:
    19
    Thank you very much.
    I will proceed with the method you have taught me for the time being.