Search Unity

Race Track, Level Building Approach.

Discussion in 'Game Design' started by renman3000, Jun 28, 2018.

  1. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Hi,
    If you were to build a racing type game, that required a track, for the player. Where the track is "safe" and the off track is "unsafe"... I am trying to figure out how to best construct this, in terms of colliders.

    I say colliders as I am using physics, so gravity, comes into play. The vehicle needs to sit (or in this case float above) or on the road.
    That said, I am looking to limit the amount of colliders I use.
    I imagine I could use a grid system, where each say 10x10 (x,z) area can be filled with a prefab, but still that would not account for roads corners, which would need both on and off area, with in.... ....


    hmmm, so many questions.
    Can anyone relate?

    Looking to save time in dev/level building and efficiency on the engine.
    Thanks!
     
  2. verybinary

    verybinary

    Joined:
    Sep 23, 2015
    Posts:
    373
    is there uphill and downhill in this track(s)?
    if not, this will be easier. you could use a giant plane to keep the car out of the abyss. if up and downhill, you would need more colliders. depending on how many vertices in your track, a mesh collider is an option. if the tracks are pretty detailed, you might can make a copy of the track mesh, slim it down some, and use it as an invisible collider with the same position as the visible, but non-collider mesh.
    the unsafe areas can be marked with invisible box colliders. if the car is inside, speed = speed x .5 or whatever
    it will need gravity unless its its like forsaken 64, so you will need either a cylinder collider on each wheel, or a box collider encompassing all the wheels and the main part of the body.
     
    renman3000 likes this.
  3. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    @verybinary Hi, yah the issue for me more so is the different type of colliders required.... meaning, main road and off road. One will allow full velocity, one will not.
    A simple ray cast down via the vehicle is how I am checking...

    At the moment, I am leaning towards a modular approach. One that will have me use sections, a corner, a straight, a grass patch etc. and place them manually thru the level.


    Thoughts?
     
  4. verybinary

    verybinary

    Joined:
    Sep 23, 2015
    Posts:
    373
    I would duplicate each mesh within their files, and simplify it to get rid of unneeded faces, separate that mesh into "road" and "offroad" so I can grab the name of the object with the ray to compare and get game logic for physics. the duplication is still to make it invisible, and so your mesh collider wouldn't have flowers, fence posts, and other decorations(the posts would get a box collider around the whole fence to save collider faces around the cylinders), and so you can make the collider simpler all around.
    I would also benchmark test multiple raycasts in corners, or at each wheel to see if it would be beneficial for offsetting "Im not still on the road, why am I driving like I am" scenarios. based on projected hardware, it might lag too much, but as of right now, I know nothing about your scenes or tracks or preformance
     
    renman3000 likes this.
  5. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697

    Hi, I have heard from another to lose the colliders on the meshes of the track and do as you say. I suppose the only (correct me if I am wrong), benefit is losing the number of colliders that might exist in a track, course.



    So, can you clarify on how to do this? I am thinking any number of meshes, might just be in fact SpriteRenderers, not any model per say.
    Thoughts?


    Overall, can you PM me or contact me at contact@yahmangames, so we can discuss this further? Or remain here if you like. I am just trying to truly get what you are suggesting.



    As for my scenes, tracks, level design.... that has not been decided yet. Tho, if I had to do it right now, I would create either models or sprites (undecided) of sections of a course. Each section is identical on overall size (10x1x10) for example. With each covering the same area of floor space, and each representing a portion of the track, I can create infinite tracks, by just placing the required section, where I desire.

    My idea, if continued, alone right now, would be that each section would have a collider, and my vehicle would ray cast down, to see if "on" or "off" track.


    Make sense? How would your approach be any better? Thank you. !!
     
  6. verybinary

    verybinary

    Joined:
    Sep 23, 2015
    Posts:
    373
    we can keep it here in case anyone has better info, or someone with this problem googles it.
    you need colliders. they keep the car from falling into the abyss. what you probably don't need, is 10000 colliders on your 10000 face track piece. each face in your model is "kinda" 1 collider.
    so take your 10000 face model track piece, make a duplicate(ctrl+d in blender for example) hide the original, and rename the duplicate to collider. now turn those 10000 faces into 100 faces. you don't need all the detail that you have in the original, you might even can get by with 1-10 faces depending on what the piece of track looks like.
    now unhide it, import it into unity, you should have your track, and your collider. go to the collider, turn off the mesh renderer(or delete it if you want to(not recommended so you can turn it back on if you need to see it for debugging purposes), and add a mesh collider to it. now make sure your 10000 face original does not have a collider on it and.
    what this does in unity, is draw your track, and draw your invisible collider. colliders take soooo much more work to keep up with. this is why you trimmed the colliders down to 10 or so. they are invisible and you have still the detail you want with your track.
    its the same as putting a box collider around a 10000 face player mesh instead of a mesh collider. you don't need 10000 points of collision and you don't want the engine having to keep track of all those faces. the 6 that comes with the bux collider is sufficient enough.
     
    renman3000 likes this.
  7. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    @verybinary Thanks man. Will go over at first chance and get back to you with an in depth response, if needed. Much appreciated!
     
    verybinary likes this.