Traffic

Hi guys. I've got one question to you. Is there any chance to do traffic on tracks, like in World Racing 2 ? I think it would be nice to have something like a real driving simulator with traffic cars. I searched many websites, but I didn't find any information about this.
 
I could show you the recent code I wrote, basically it creates on fly a similar traffic ini with all the waypoints. When you drive & trigger the script, your actual car trajectory is recorded, so you end up with perfect recorded waypoints interpolations. Finally the script wraps the car. It avoids you to manually go to Tracked & set them by hand.

Playing with waypoints & traffic in Tracked, you can see how the left right waypoints etc. works, it starts incrementing the according variable (left or right) & you could build some complex conditions on junctions.
 
Attaching/getting the pbody id from all rcars + listening/getting other values (velocity gear etc)..inside a tree like ini custom file (hardcode them) via the ini console command & you should be able to simulate a real car, so that's why my actual testing traffic car was kind of 'flying' without nothing really going on, but now you know ! In fact, the body tree in our car.ini is the pbody with its mass & proxy/collision mesh....

Note, for realistic Newtonian collision events, you should build a custom collision mesh, as some of you might know, the manual box stuff doesn't do a good job, Ruud also invite us all to create such simple closed mesh (200 polies he says), but I use more to get preciser physical calculations. In CE2, we were used to create them & we had always to make those objects manually...

Here's a code coloration for Racer Scripts I made in NP++ ....
In NP++ > View > User Define, in the Keywords Lists tab, set the 1st Group with this :

Code:
pbody rcar rmovable rnode rtex rcarmodel file string int float (

2nd Group
Code:
open write sqrt pow substring length find read flush abs acos asin atan atan2 ceil cos cosh exp fabs floor log log10 sin sinh tan tanh get set remove joint add local car carcount scriptowner focus scale motion show hide echo system node warp waypointcount paint print servertime publicserver server laptime create kill after run is key send timeline qdbg trackdir spectator multiview simtime exit reset paused unpause pause random interval resolution wait command while for do if else func

3rd Group
Code:
id vel rotvel pos rot bodyforce in at to from bodyforce worldforce bodytorque worldtorque jointlimit with parent offset has joint parent freeze jointdir

4th Group
Code:
return Comment:

In NP++ > View > User Define, in the Comment & Number tab, set the 1st Group with this :

1th Input text box

Code:
//

2nd Input text box

Code:
/*

3rd Input text box

Code:
*/

Save it as Rscripter or whatever you want & apply it to any file via Language > Rscripter.
 
Traffic should work nicely, but it lacks documentation.
It's not so difficult to do.
you can create waypoints in tracked, the traffic cars will drive from waypoint to waypoint.
When you save the track, tracked will add a traffic.ini in your directory.
To add a traffic car to the scene add something like this in the generated traffic.ini:

cars
{
car0
{
; which car ?
car=bmw_m3
; start from waypoint
waypoint=0
}
car1
{
car=bmw_m3
waypoint=20
}
car2
{
car=bmw_m3
waypoint=40
}
car3
{
car=bmw_m3
waypoint=60
}
}


You can control the waypoints using scripts to create stoplights and other crazy stuff.

Have fun !
 
You can control the waypoints using scripts to create stoplights and other crazy stuff.

Let's say, in the case of Freehand track, there's some 100 intersections/crossings multiplied by 8, to set 4 triggerlines + 4 stoplights (1 skeleton/bone sphere ? 1 half red / 1 half green rotating 180° around its CoG to switch stoplights colors ?), so just before focusing on the scripts, I'd have to place 800 objects inside Tracked, ouch !

I think I need to inverse the idea...from the terrain & all surfaces, how the scripts could know & actually automatically/randomly place/wrap traffic cars all around without worrying about the triggerlines & other objects placements...something that does the job 'on fly' & is conscious/listening to its own actions/events for precise error/bug handling (traffic cars blocked/stuck together somehow i.e.) ...
 
You are right, but that is up to you.
The tools are available to create a functioning traffic system, im very curious to see what you make of it.

Since the traffic.ini is a very simple format, only containing xyz, indexing and simple flags, you can fairly easy generate waypoints from available trackdata or any way you want

I'm standy for any questions regarding this topic.
 
waypoint flags:

F_CANT_PASS_RANDOM_ROUTE=1, // this waypoint is blocked when planning random routes
F_CANT_PASS_DYN=2, // this waypoint is blocked dynamically (stop lights, road obstacles, ...)

so if you want a waypoint that is default blocked for route calculation :
Code:
  waypointX
  {
    pos=23.615423 -0.000045 -80.542213
    forward=2
    left=-1
    right=-1
    flags=1
    velocity=13
  }

to combine both flags:

flags=3
 
F_CANT_PASS_RANDOM_ROUTE=1, // this waypoint is blocked when planning random routes
F_CANT_PASS_DYN=2, // this waypoint is blocked dynamically (stop lights, road obstacles, ...)

I'm not that far yet, but that refers AFAIK to :

Code:
set waypoint (int) can pass randomroute (int)
Comment:
Set if waypoint is blocked when calculating routes.
 
set waypoint (int) can pass dynamic (int)
Comment:
Set if waypoint is blocked for passing cars (cars will stop at this waypoint).

Thanks Mitch, 1st traffic cars (4 for now) working here with no overrun, randomly wrapped to WP & looping.

Still, there's so much I need to learn, so I began my research about the most famous worldwide know AI simulation IDE & classes, there's a plenty of already written & open source code for realistic & complex AI engineers, creators/coders, mostly for us, game devs.

I discovered that Crytek Engine which I've used to test AI & do some dynamical simulations (force fields...) has implemented some of the xaitment AI code ; the source code seems available :

http://www.xaitment.com/english/blog/blog.html

Here's some of my ideas combined with existing ones

- Easing of AI traffic cars (smoothing fom 1WP to another or across multiple WPs)
- Awareness/Sensoring of AI cars => Detection & Avoidance of collisions (car virtual collision radius based on car actual dimension)
- AI cars velocities related to actual traffic density (intelligent, self regulated & recalculated routes to avoid traffic jams situations)
- Smart & random AI spawning/destruction not visible to player (traffic cars aware of actual player)
- Smart traffic layouts designs for Racer => manually or scripted/ingame oriented designs ?
- Graphical objects used as helpers for fast visual debugging (stoplights, fluidity...)
- Traffic frequency/density related to the time in Racer (night less traffic, rush/peak hours...if time=0200 $traffic_fluidity = 0.1 //10 percent)
- Analysis & tracing functions for a fast & easy visualization (cars stopped, cars above a certain velocity, cars crashed/blocking routes/WPs/roads...)
- Cars & Pedestrians interactions based on triggerlines events in specific places
- Opportunist crossing situations (pedestrians unpredictable behaviour / allowed to cross anywhere from sidewalk to another, if both detecting radii aren't intersecting...)
- Cars + skeletal pedestrian interactions/collisions events & detectors => triggering of another skeleton animation when hit by car ?...)
- Integration of signs & custom events triggering (50 km/h max., zebra crossings where no stoplights are found...)
- Simulation of Non-Lane based traffic (use of the full width of roads, zig-zagging (bad driving behavior !) enabled/randomized & factorized...), dynamical splitting & creation of virtual scripted lanes according to car/road width...
- Simulation of illegal racing cars & police i.e. overruling the global traffic car rules (dangerous & higher driving skills, dynamical radius for preciser/quicker/more predictable collisions avoidance, smarter route recalc...)






PTV Vision YouTube Channel Videos :
http://www.youtube.com/user/ptvvision#g/u

Worldwide most famous AI engineering apps :
http://www.xaitment.com/
http://www.ptv-vision.com/software/...tware-system-solutions/vissim/example-of-use/
http://www.paramics-online.com/paramics-product-tour.php
http://www.caliper.com/transmodeler/default.htm
http://www.clranalytics.com/
http://www.tno.nl/groep.cfm?context=thema&content=thema_cases&laag1=894&item_id=894&Taal=2
http://www.ptvag.com/software/trans...ing/software-system-solutions/vissim/enviver/
http://www.trafficgroup.com/about/index.html

If you have some existing code examples which relates to the ideas, showcase it !

=====================================
Questions about Traffic

- Unsized arrays, can't you declare like C++ ?
- Multi-dimensional arrays ?
- Pointers ?
- The most efficient ways of handling complex arrays ?
 
Arrays are very basic at the moment.
There is no such thing as a dynamic arrays, multi-dimensional arrays, or pointers in RScript (yet).

The examples you are showing are complex, and not possible with the available tools.
Some complexity is possible at the moment, but not as much to call it intelligent.

I was expecting a more modest attempt for traffic ;)

I'm very interested in this, im gonna think about what is possible in the future
 
Interesting reading, I'm playing around with an revamped Broken Springs carpark track, with about 4x the area of the original. I would like to (eventually) use traffic AI to run cars around the track, possibly able to park in parking spots, then leave after a period of time; also I'd like to run an AI trolley tractor or two around, which need to stop at intervals to collect trolleys; buses & delivery trucks similarly, and possibly an elderly person or thre on mobility scooters on pavement areas.
What is currently doable out of this, what will be & what never will be?
 
It's a good question...
I think it depends how you envision the project, I guess with some trickery & advanced knowledge of all commands & scripts, we can do some amazing stuff.

It's kind of surprising we have no real examples to show us how we should design the traffic layout.
So, I'm hoping others will follow me, because right now, everyone is so silent & somehow frustrated not been able to deploy fully the whole Racer power into reality.

Here's my code which boost your waypoints design, deleting completely the need for designing it via Tracked.
Careful with the code as it can generate huge # of WPs / s....:)
Consider also, that this script with some variations, could be a custom replay script, a custom spline ini for AI cars, etc...Think about it !

Set a triggerline some meters away from your 1st grid line & paste this as command :
run data/tracks/carlswood_nt/scripts/paint/wp.rcx

wp.rsx :

Code:
// Racer Script to create a traffic.ini file with all WPs
// The idea is to set this file by driving ingame instead of manually positioning the WPs.
// By QuadCoreMax 2012
 
rcar $c = get local car
int $pos = 0
 
// traffic.ini values
int $f = 0
int $r = 0
int $l = 0
int $fl = 0
 
while 1
{
    // Get Position of car & extract each xyz values
    float $pos_c[3] = get $c pos
 
    // Swizzle
    float $pos_x = $pos_c.x
    float $pos_y = $pos_c.y
    float $pos_z = $pos_c.z
 
    // Conversion from float to string
    string $sx = $pos_x
    string $sy = $pos_y
    string $sz = $pos_z
 
    // You can specify '$' for the value, which is translated to an empty string (to clear settings).
    // Use the '$' sign inside values to represent a space, i.e. 'ini race.ai_car_multiple car1$car2$car3'.
    string $s  = "$"
 
    // Combine car pos xyz values into 1 string
    string $r = $sx + $s + $sy + $s + $sz
 
    int $i = 0
    // for $i < 2/4 will increase the WP numbers - CAREFUL
    for $i < 1 do $i++
    {
        $f++
 
        // Creation of custom route/waypoints
        // Traffic.ini file created in root folder
 
        send "ini traffic.ini waypoints.waypoint" + $pos + ".pos " + $r to console
        send "ini traffic.ini waypoints.waypoint" + $pos + ".forward " + $f to console
        send "ini traffic.ini waypoints.waypoint" + $pos + ".left " + -1 to console
        send "ini traffic.ini waypoints.waypoint" + $pos + ".right " + -1 to console
        send "ini traffic.ini waypoints.waypoint" + $pos + ".flags " + 0 to console
        send "ini traffic.ini waypoints.waypoint" + $pos + ".velocity " + 10 to console
 
        $pos++
    }
    interrupt
}

Enjoy this script which interpolates & makes the WP layout theoretically IMPOSSIBLE to create with hands. ;) The file (ini) is created in the root folder & you just need the count=... set correctly when you move it to your track folder.

Since I'm using the ini command, was wondering why you hadn't integrate all the ini.exe functions into scripts ? Please do it so....

Reading; 'ini <file> <key>'
Removing; 'ini <file> remove <key>'
 
It's kind of surprising we have no real examples to show us how we should design the traffic layout.
So, I'm hoping others will follow me, because right now, everyone is so silent & somehow frustrated not been able to deploy fully the whole Racer power into reality.
No, Racer's generally like this always, development takes precedence over documentation.
Personally, my interest for now is academic, new carpark's not even in Racer yet, just a bunch of zmod meshes atm; and as Mitch is working actively on the traffic system, I was more letting him know what I'd want it to be capable of near future.
 
I'd happily develop some traffic stuff when I have some time.

Why not do something with Roggel for example, then at least you can share it and then others can throw in their 2p and develop stuff on top of it...
It's great to develop ideas in isolation but you ultimately have to share stuff too, and Roggel seems like a great platform for super simple AI for now.

Perhaps even make a super basic dual carriageway with a roundabout at each end, or something like that?

Trying to make an entire city run traffic as your first try is gonna be hard. I'd start at a car driving up and down a road and be more than happy with that as my first attempt that went well :D

I don't even know where to start for now hehe :)

Dave
 
About working actively on Racer ...
I'm not working at Cruden anymore, but Cruden and Ruud allow me SVN acces so i can develop things if I feel like it.
The good thing is, i can work on what I want, and you need. The bad thing is, I have had little or no time the last months to develop for Racer since life is keeping me busy.

But I am planning on making some time available to develop for Racer in the future.
 

Latest News

Are you buying car setups?

  • Yes

  • No


Results are only viewable after voting.
Back
Top