Search Unity

City Traffic System - Physics based cars

Discussion in 'Works In Progress - Archive' started by MD_Reptile, Dec 3, 2012.

  1. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664


    I have been hard at work on a unity traffic system, called uTraffic.

    Here is a quick video to show the AI on a race track, where I have been fine tuning the steering to allow for higher speeds without losing control:



    In this video you will see a cube that follows a spline path in front of the vehicle, which im calling the "guide cube" :p Which sort of acts like a drivers desired location, while allowing for room for error in his steering, so he wont steer too tight or too loose to make the turns. And you can see that they are getting much better than in the previous webplayers! Now I am focusing again on a new city scene, to improve the low speed control more, and hopefully I will be back in a few days with another update, showing better city driving.

    Any comments/suggestions are appreciated.

    PS the reason that level (the one provided with unity demos) lacks a lot of the geometry for the environment is I had problems getting that level to import properly, so ended up deleting a bunch of missing texture objects and such.

    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    OLD STUFF:

    the old webplayer (way outdated, poor AI steering and obstacle avoidance)
    http://ninjeticstudios.com/WebPlayerAIDriver/Webplayer/webplayer.html
     
    Last edited: Mar 6, 2013
  2. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,887
    Cool, but get that turning circle fixed :p.
     
  3. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    thats my first priority right now, I am already keeping track of the "last waypoint" so what i am thinking is, not trying to just point at the next checkpoint, but to keep on track of the line between those two waypoints.....hmmm
     
  4. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    For the cars turning not straight after, add a waypoint where each pinkish dot is. That should straighten it out.
     
  5. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    Your right, I will see how it works this way. I am thinking it might have to consider some waypoints more important than others perhaps, as well as sometimes turn tighter, sometimes a little less depending how far from the waypoint they are, rather than how close in angle they are...

    Thanks for the suggestion, I will keep on updating things frequently, and if anyone wants to suggest any tools/scripts that help me to simply draw a curved line, maybe a bezier, between points, that would be nice!

    Maybe something like this (couldn't make this work):

    http://www.frictionpointstudios.com...ier-curve-now-in-easy-to-use-prefab-form.html

    oh PS got that working but it didnt suit me, its nice though!
     
    Last edited: Dec 6, 2012
  6. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    BUMP big update, try the new webplayer upload. I will post more info later!
     
  7. ProjectSHiNKiROU

    ProjectSHiNKiROU

    Joined:
    Dec 5, 2011
    Posts:
    7
    I found the car turns left and right.

    For controlling, maybe add a margin of error, so that when the car is within the margin of error, it will only try to straighten the direction parallel to the road.
    Or, you can try a PID controller, and you can tune the PID controller while you are in play mode.

    http://en.wikipedia.org/wiki/PID_controller#Pseudocode
    http://www.google.ca/url?sa=t&rct=j...ioCABg&usg=AFQjCNErJuRhVXFNpvs78ibHuDTh4d8vDQ

    Real drivers also slow down before turning, and there is a way to calculate turning radius based on coeff of friction and speed.
     
  8. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    yes for sure there is much more work left in the AI and its steering, when I say "its much better" its very relative lol, before they were terrible, just terrible, now they can sort of navigate proper, but the faster tighter turning vehicles (the lambo) need some modifiers to allow them to be more accurate for sure - and the avoidance must see some work too. But now that I have gotten past some difficult parts (getting the AI drivers to even respond properly and aim themselves properly) and got some obstacle avoidance running (for now only a single ray from the front of the vehicle) to stop from rear ending each other - I will be focusing more attention to the waypoint layout (right now its a bit funky in certain turns) and how the AI manages the straights all wobbly, plus allow easy waypoint operations like adding new waypoints a little easier (right now its copy paste and edit stuff haha). Not to mention the accel and braking both need smoothed, as of that webplayer they are not smoothed in any way, either 100% gas or brake or 100% coasting. That wont be hard to implement in comparison to the steering, which I why I got the basic steering done first,

    Oh and that first link is interesting, the second doesnt work for me.

    anyway I will be posting another, hopefully finer-tuned webplayer here after some tinkering.
     
    Last edited: Dec 6, 2012
  9. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    BUMP - Update, working hard on a new "guided" system for steering between waypoints. See the first post!

    Thanks to ProjectSHiNKiROU for suggesting PID - good stuff!, have been using it since I read the articles you suggested, and found a working PID system by Andeeee on the forums here somewhere
     
  10. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    Bump - still been working at the system, decided to purchase "sws" on the asset store, which has improved waypoint editing and creation severely, plus allows curved paths for my guide objects to follow, improving the overall steering of the vehicles. No new webplayer today, but when all the kinks are worked out with switching to sws waypoints, I'll share another webplayer to see what you guys think.
     
  11. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    Any updates to this system?
     
  12. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    Yes - just posted a video to show some work I have been doing with the system. Right now I am working again on a city scene, but in that video I show a driver on a race track at higher speeds than you would expect traffic to go, in order to get the steering better at higher speeds. I think its starting to work pretty well!
     
  13. dibdab

    dibdab

    Joined:
    Jul 5, 2011
    Posts:
    976
    the guiding cube sound like a good idea but in sharper curves the car still takes quite a sharp turn
     
  14. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    Yes it is still not perfect. I'm trying a system to replace it now, which is more like xiat system ( or maybe i read this about the one in midtown madness...can't remember), using a single spline for each road, only using offsets for lanes, making it easier to implement a new city, and easier to keep lanes from accidental intersection (causing cars to come to close in opposing lanes). This is tricky though... Give me time to get it right :)
     
  15. dibdab

    dibdab

    Joined:
    Jul 5, 2011
    Posts:
    976
    thats some sws code, right? its js or c+?

    I was using distance/angle for this.

    if it is done right, 'driver style' can be written for ai.

    so its spline for road (a vector) and distance (offset) - it might eat up a bit update time (like raycast).
     
  16. dibdab

    dibdab

    Joined:
    Jul 5, 2011
    Posts:
    976
    isn't it that offset is connected with the steering? get it conditional on obstacle/semaphor/etc tag - and write it into the driver style.

    now I was trying to come up w a solution to waypoint management. so it doesn't just use from the waypoint list, but switches to another waypoint(s) - basically different routes within the same waypoints
     
    Last edited: Mar 6, 2013
  17. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    I am using sws with a custom hoMove component to control the guide box yes. It remains a certain distance from the vehicle while following a spline path.


    I'm using only a single route on this track, however i do have a way to switch between separate paths implemented, is that what you mean?
     
    Last edited: Mar 6, 2013
  18. dibdab

    dibdab

    Joined:
    Jul 5, 2011
    Posts:
    976
    you got it done?

    can you share that code or whats the method behind it? is it sg like different waypoint containers (aka routes) or dynamic (L/R lane way) waypoint selecting?


    ............
    I'm guessin you can make a search for closest waypoint in (-60,60) angle range headway
    but still wouldn't want to call it every time crossing a waypoint
    and still would need to crossreference the target location (could check angle, then choose waypoint. not a smart gps, but at least tries to move that direction)
     
    Last edited: Mar 6, 2013
  19. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    I have not decided if this will ever be public, that depends how hard I work on it, and if it becomes commercial quality or not. I'd love to talk about how it works, ask any questions if you want to know more about it, but for now its far from complete, so no release any time soon.