Search Unity

Question Handling LayerMasks on terrain?

Discussion in 'World Building' started by TheProcessYet_64, Dec 7, 2023.

  1. TheProcessYet_64

    TheProcessYet_64

    Joined:
    Jan 4, 2023
    Posts:
    45
    I am trying to find out if there is a way to have multiple LayerMasks on a single terrain object or what the workaround would be for that.

    Right now I have player movement using a
    SphereCast
    based on whether I am standing on a flat surface or on a slope (for slope sliding) and I have Layers for both which are Ground and Slope. If I am standing on a flat surface, then the Slope Layer can never function.

    But on a terrain object because there's only one option for a Layer, how would I separate flat ground and slopes if I decide to use the Paint Terrain option and raise terrain to form a few hills/mountains? At the moment there are a few brief instances where my player stutters where the flat ground and slope first meet at the base.


    In this photo the only solution I can think of is adding invisible box colliders between the slope/tall hill to the left and my player so that technically a wall is detected as opposed to a slope.
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,927
    I would not use layers for this. Better to use raycasts and use the normal of the output
    RaycastHit
    to calculate the angle of the ground under the player.
     
  3. TheProcessYet_64

    TheProcessYet_64

    Joined:
    Jan 4, 2023
    Posts:
    45
    Thanks for the reply. Wouldn't that only partially work because the Raycast doesn't have the 360 degrees range that the SphereCast does so it would stop detecting angles near the bottom of hills/slopes/mountains etc while the player is still technically on an angled surface?

    upload_2023-12-7_12-40-46.png

    But then using a SphereCast also has its own issues like in my post where it's detecting angles when and where it should not so I'm stumped.
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,927
    I did say raycasts, plural. You can use more than one.