Search Unity

Question Car surface detection

Discussion in 'Editor & General Support' started by henners999, Mar 20, 2023.

  1. henners999

    henners999

    Joined:
    May 30, 2020
    Posts:
    72
    For an overhead racing game in 3d, what is the best way to detect change in surface given the level is constructed in Blender as 1 large plane?

    I'd like to detect whether the car is on asphalt, grass, sand surfaces but also smaller ones such as drains and puddles.

    Ideally something easy to map out in either Blender or Unity. Materials seem out as there's not a mesh for the road, grass. Colour coding makes sense but unsure if that's even possible. Any ideas?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
    Color coding is possible, not ideal however.

    You may wish to make a series of invisible GameObjects with Collider2Ds (configured to not collide with anything) that you check with one of the many Physics2D.Overlap*() calls, and each collider would have a Component that tells what kind of surface you are on.
     
  3. henners999

    henners999

    Joined:
    May 30, 2020
    Posts:
    72
    As the game is 3d I guess the same would translate? The object would just 'lie' on the ground object
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
    Lie on or overlap... you should make a small pilot test to see how it all sorta works together... it should be pretty good.

    In the future you could get clever with OnDrawGizmos() and whatnot to have these colliders show specially in the scene window so you can reason about whether you have marked things properly.

    You can use layers to mark colliders as not colliding with certain other-layered objects. See the physics collision matrix for more details.
     
    henners999 likes this.
  5. henners999

    henners999

    Joined:
    May 30, 2020
    Posts:
    72
    Perfect, got something to get my teeth into finally! Shall report back no doubt... ;)