Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Procedural Generation - Parse File Input --> 3D Track with variable speed moving car

Discussion in 'Windows' started by the.blues, Oct 17, 2014.

  1. the.blues

    the.blues

    Joined:
    Oct 16, 2014
    Posts:
    6
    I am a Direct2D/C++ programmer and migrating to Unity3D as a new-bee.

    For a 3D Simulation/Animation application for my student project, I would be having a text file, where the format would be something like

    Length (in meters) Curvature(Angle°) Slope(Angle°)

    1000 0 -20 (minus for downhill)

    300 -20(minus for left) 0

    500 5 30

    which means for 1 kilometre the street is straight with 20° downhill. The next 300 meters the street has 20° curve (no uphill and no downhill). After that for the next 500 meters the street has 5° curvature towards right direction with 30° uphill. The landscape (trees, traffic signs, buildings and neighbourhood) is optional. Only one car (our car) is driving on the street.

    The car moves in a variable speed on this generated 3D track, which should be viewed from chase cam view and driver view (which is configurable). I would like to achieve something like this, for example.



    Based on my research as a student, procedural generation is the only solution to generate the 3D track based on parsed file values.

    1. I would like to know if this requirement can the implemented using Unity3D.
    If yes, possibly using scripting (C# or JS)?

    2. If yes, are there any samples that have been already made similar to this concept.
     
    Last edited: Oct 17, 2014
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,935
    the.blues likes this.
  3. the.blues

    the.blues

    Joined:
    Oct 16, 2014
    Posts:
    6
    Obviously you mean, my requirement is possible with Unity3D? I could also dynamically configure the camera view (chase cam view or driver view).
    Later:
    1. if I want to add traffic signs and a less detailed landscapes (some trees)
    2. run another car along with the main car.
    ?
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,935
    Yes, its all possible with unity.

    You could for example procedurally build the terrain heights, add trees to it (near roads) and other objects too..

    Camera is easily adjusted (position, rotation, fov and others)

    And you could even build dll library with c++, for example to process the data (since you are already familiar with c++, but this might require pro version)
    and then just feed unity the vertices or other data to actually build/display the mesh..

    Also in the asset store there could be several tools ready to use for that,
    road builders, traffic AI, etc..
     
    the.blues likes this.
  5. the.blues

    the.blues

    Joined:
    Oct 16, 2014
    Posts:
    6
    Thanks again, http://stackoverflow.com/questions/3886611/blender-vs-unity
    According to this 2010 article, "Do the modelling in Blender and import them in Unity to build the game".

    In my case, should I need to learn them both? How relevant is Unity when compared to Blender, according to my requirements.
     
  6. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,935
    You can grab free (or paid) trees, cars, other models from asset store or anywhere and use them in unity,
    and for your requirements, no need to use any 3D software on your project (unless you must have some specific custom 3D model added there)

    Of course you could build the road outside unity too and just import to unity,
    but if the input data changes, then you need to rebuild & re-import new road again,
    while if you create a road builder script in unity, you just parse the text file and road appears as it is : )
     
    the.blues likes this.
  7. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,491
    Blender in this case would be your modelling software, where you make the trees, cars, generate normal maps, etc. You can use any 3D modelling software for the job. Blender is popular because it's free.

    Once you have the models ready, you can import them to Unity to make your game.
     
  8. the.blues

    the.blues

    Joined:
    Oct 16, 2014
    Posts:
    6
    I thought, programmatically I would be generating the track using Bézier curves (or similiar mathematical approaches) in Unity and apply the textures on the fly to the track.
     
  9. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,491
    For that, you will not need 3D modelling software. However, I'm pretty sure you won't be able to do the same for trees or cars :).
     
  10. the.blues

    the.blues

    Joined:
    Oct 16, 2014
    Posts:
    6
    Two more question still:
    1. The track model will not be available at the start of the application, only at run time. Even in this case, can I tell Unity3D to move the car and the camera (which were modelled in advance) "on-the-fly" in chase cam view, just when the track is being programmically rendered?
    2. Do I need to purchase UnityPro for my requirment? i.e. less detailed landscape, as it is a student project.
     
    Last edited: Oct 17, 2014
  11. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,491
    1. Yes.
    2. Everything you mentioned can be done in Unity Free.
     
  12. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,935
    And you have several options for (1)
    - Build the track everytime the application is run
    - Build the track only first time the application is run, then save it to disk ( http://wiki.unity3d.com/index.php?title=MeshSerializer2 ), on next run load the saved mesh
    - Build the track in editor playmode (and save as assets/meshes/prefabs with script)
    - Build the track with your own editor plugin (builds the mesh into scene, can work with them as with any gameobjects and place cars & cameras there)
     
    the.blues likes this.
  13. the.blues

    the.blues

    Joined:
    Oct 16, 2014
    Posts:
    6
    1. Generate Procedural Mesh using Béziercurves (or similar mathematical idea), by feeding the coordinates, after parsing text file.
    2. Track is now generated with needed curvature without texture.
    3. Apply appropriate 2D texture (Lane markings, road material, lane width) on the prepared track.

    To visualise uphill and downhill of the track, do I need to apply the concepts such as the height map on the dynamically prepared track or still use Bézier curves (or similar mathematical idea)?

    http://www.gettyimages.de/detail/illustration/car-racetrack-lizenfreie-illustration/157111198