Search Unity

Traffic simulation

Discussion in 'Works In Progress - Archive' started by carking1996, Dec 30, 2013.

  1. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    Just wanted to show off a traffic simulation I made with generous help from the community. :)

    *Note: Lag only caused by video capture. Lag is not present in game simulation.

     
  2. KheltonHeadley

    KheltonHeadley

    Joined:
    Oct 19, 2010
    Posts:
    1,685
    I've played around in this, works really good. Really fun to just drive around and avoid crashing.
     
    Deleted User likes this.
  3. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    Edited:

    PM me for standalone link.
     
    Last edited: Jan 29, 2014
  4. Ethaninja

    Ethaninja

    Joined:
    Jan 7, 2013
    Posts:
    277
    That's really nice man! I need something like this for my car-combatants game I'm working on. I'm guessing you used raycasting for the traffic to avoid obstacles and just paths for the roads or something?
     
  5. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    Yes! Raycasting is used to detect objects. Paths per road are used, then paths are assigned at the beginning of an intersection.
     
  6. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    Very cool Carking, I would love to see more info on how it works, what makes this thing tick? Agent driven?

    Oh i tried getting the webplayer going, but it didn't work for me, i hit "cruise" and it took me to an empty room, where back and drive were the options, but drive didnt seem to do anything, hit back, then tried "race" but that also did nothing for me :/
     
    Brainswitch likes this.
  7. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    The vehicles are based on 1 set of 4 waypoints per street(4 for a 4-laned road, or also 2 for a 2-laned road). The web player is down, I should probably remove that link. :p

    Everyone, the system is for sale! PM me to check it out! :)
     
  8. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    Here's another stress test of my Unity3D traffic simulation system. On the screen are just under 60 vehicles driving themselves around the environment. The only limits to the amount of vehicles are your vehicle draw culls, but that's for you to get down. :)

    Updates are random turning for right lanes and optimizations. I think it shows well!

    Webplayer link: https://dl.dropboxusercontent.com/u/30521755/Traffic/eb.html

     
    Last edited: Apr 6, 2014
  9. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    I have decided to model a city around it. Take a look!

     
  10. Stopsecret

    Stopsecret

    Joined:
    Oct 31, 2012
    Posts:
    70
    Looks good CarKing! :D Are they rigidbodies? Fully detailed cars with whellcolliders, or just transforms with colliders and raycasts? Also, the cars seem to slow to a stop way too quickly behind other cars, but maybe I'm just a weird driver in real life ;)
     
  11. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    They have full physics, wheelcolliders and rigidbodies. Here's another video.

     
  12. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    Some updates:
    -Stop signs work. Vehicle checks if traffic is on the road. If there are traffic, it stops and waits. If not, it just goes.
    -Tail light implementation.
    -Random speeds based on Random.range.
    -One-way streets work now, too.

     
  13. SmellyDogs

    SmellyDogs

    Joined:
    Jul 16, 2013
    Posts:
    387
    Super good job. Can you show how you setup roads.
     
  14. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    I'll show a video later. I'm also adding pedestrian support tonite.
     
  15. SmellyDogs

    SmellyDogs

    Joined:
    Jul 16, 2013
    Posts:
    387
    It looks slerp/lerp based rather than physics based. Is that correct?
     
  16. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    Nope. Full wheel collider physics. I've created this in less than two minutes with the editor pieces I wrote.

    $yjnIm4r.png
     
  17. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    Here's a video of it in use. :)

     
  18. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    Testing out the pedestrian simulation. :)

     
  19. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    Bump. Whatcha guys think?
     
  20. jolo309

    jolo309

    Joined:
    Mar 4, 2012
    Posts:
    94
    I like it alot :) Keep it up, the only thing i don't like is the pedestrains because they all go the same path, but that can probably be changed, not sure but i bet it is a work in progress :)
     
  21. SmellyDogs

    SmellyDogs

    Joined:
    Jul 16, 2013
    Posts:
    387
    More variation in pedestrians moving, also maybe more realistic car physics? Pretty hard I know.
     
  22. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    Some things I'm planning:

    -Taxis with stops
    -Buses with stops
    -Peds sitting on benches
    -Peds standing around, talking

    Thanks for your comments, guys. :)
     
  23. fred_gds

    fred_gds

    Joined:
    Sep 20, 2012
    Posts:
    184
    This system looks great.

    Is it already available. If so where can I get it?
     
  24. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    It's for sale. You can PM me for any questions. :)
     
  25. Cheetoturkey

    Cheetoturkey

    Joined:
    May 15, 2013
    Posts:
    54
    Ive seen this in action, and i definitly recommend buying this!
     
  26. rafaelmfernandez

    rafaelmfernandez

    Joined:
    Aug 11, 2013
    Posts:
    62
    Hey I am currently using this, is there anyways to loop paths and/or delete at the end of the path?
     
  27. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    The paths currently do not loop, but I have a AI code that does, or you can just set the PathSelector at the end and begin the path again. And you can make it delete your car at the end if you need.
     
  28. rafaelmfernandez

    rafaelmfernandez

    Joined:
    Aug 11, 2013
    Posts:
    62
  29. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    Yes, just add the path selector trigger and script on it. :) Check out the intersections, as they have them.
     
  30. rafaelmfernandez

    rafaelmfernandez

    Joined:
    Aug 11, 2013
    Posts:
    62
    Hmm, Ill try that, last time I tried to do something with the path selector I clicked it on the UI and nothing happened, and which script are you referring to. Sorry, still trying to get the ropes :)
     
  31. Goregaming

    Goregaming

    Joined:
    Sep 6, 2012
    Posts:
    243
    Looks pretty good
     
  32. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    Hello, here's an image of what you could do. Go to the objects inside the traffic light object with this script, "GetThePoints". This script allows you to assign a path to which the traffic in that lane will go to. Simply make the path almost closed, and put one of these triggers with the script(assigned to the path), at the end. It will then simply go to the same path over and over without stopping.

     
    rafaelmfernandez likes this.
  33. rafaelmfernandez

    rafaelmfernandez

    Joined:
    Aug 11, 2013
    Posts:
    62
    Whats the latest version? I tried that last night but even in the demo after the first trigger all the cars just veer off onto the sidewalks or into each other. Is it possible you can send me an updated version?
     
  34. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    The demo scene isn't really much of anything. It's a few roads not even connected. I should redo it.
     
  35. rafaelmfernandez

    rafaelmfernandez

    Joined:
    Aug 11, 2013
    Posts:
    62
    Ok I will try what you said, and let you know.
     
  36. rafaelmfernandez

    rafaelmfernandez

    Joined:
    Aug 11, 2013
    Posts:
    62
    Ok I have been trying all day to get the cars to get on a path from the trigger like you showed buts its simply not working everytime. This is the result everytime :







    I did both the first point on the path in the get points variable and the whole path itself, I also checked, unchecked navigate and get points and still the same thing. Please let me know if you see something Im doing wrong
     
  37. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    Can you show a video on what you're doing? You don't set the first point. You set the whole path object, the parent of the path.
     
  38. rafaelmfernandez

    rafaelmfernandez

    Joined:
    Aug 11, 2013
    Posts:
    62
    Ive sent you a PM with the video link.
     
  39. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    Still looking great! One thing I would suggest is to make a naming convention for the "paths" and "intersections" objects, so they follow a scheme like Path_001, Path_002, Intersection_001 and so forth. Other than that I am really impressed how far you have taken this project! Could I ask publicly what the price of the asset is? And are all the models and scenes in the video demos available when you purchase?
     
  40. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    I've sent you a pm. :)
     
  41. murat303

    murat303

    Joined:
    May 22, 2014
    Posts:
    38
    Hi, when i switch the project to Android, i get this error;
    AICar_ScriptTr.js(50,28): BCE0019: 'transform' is not a member of 'Object'.
    AICar_ScriptTr.js(51,45): BCE0019: 'transform' is not a member of 'Object'.
     
  42. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    Replace line 18 in the AI_CarScriptTr code with:

    Code (JavaScript):
    1. private var waypoints : Transform[];
     
  43. murat303

    murat303

    Joined:
    May 22, 2014
    Posts:
    38
    this time another error;
    IndexOutOfRangeException: Array index is out of range.
    (wrapper stelemref) object:stelemref (object,intptr,object)
    AICar_ScriptTr.GetWaypoints () (at Assets/Scripts/Car Control/AICar_ScriptTr.js:101)
    AICar_ScriptTr.FixedUpdate () (at Assets/Scripts/Car Control/AICar_ScriptTr.js:49)
     
  44. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    Odd. Let me check this.
     
  45. murat303

    murat303

    Joined:
    May 22, 2014
    Posts:
    38
    any solution for this?
     
  46. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    Still trying to figure out a workaround for it. I had fixed it for a past buyer, but don't have the exact code anymore. I'm looking for a fix.
     
  47. murat303

    murat303

    Joined:
    May 22, 2014
    Posts:
    38
    we need in a mobile project, i sent you email, It would be great if you could go back
     
  48. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    I'm still working out the bug. Taking some recoding.
     
  49. murat303

    murat303

    Joined:
    May 22, 2014
    Posts:
    38
    still does not? I think we have to look to other projects, thanks anyway
     
  50. tarc79

    tarc79

    Joined:
    Sep 6, 2016
    Posts:
    1
    Hello Carking - any updates from you on this project? Wish I saw this 2 years ago :)