playMaker

Author Topic: Need help with making Realistic AI Traffic Behavior  (Read 9111 times)

bizilux

  • Full Member
  • ***
  • Posts: 171
Need help with making Realistic AI Traffic Behavior
« on: December 23, 2013, 04:44:22 AM »
hey all,

so i'm working on bus simulator game that might be released at one point...

and in 1 day i made bus stop system, and simple system that shows you which turn you need to take at next junction, and some systems that check if you drove off lane and gives you penalty, or if you drive too fast, etc...

now im kind of brainstorming the best way to do AI traffic...

keep in mind that im making this game for mobile market... so i cant have like 100 raycasts on 1 car... and i probably wont use any physics vehicle system for steering cars...  (im using edy's vehicle physics for bus, but i cant use edy's vehicle physics on AI cars, because it doesnt scale well, so i will have to find other solution... i guess i can just do it without any vehicle physics at all...)


anyways, what do you guys think would be the best way to do AI traffic with playmaker?


right now i only came up with one idea, and that is to use iTween, and then basically have triggers before road turns, so that the car slows down a bit, that it doesnt just take the turn at full speed, and also to have raycasts on cars, basically only front direction is needed i guess...

for junctions with traffic lights i would use triggers that would put speed of cars to 0, that aint a problem...
a bit bigger problem would be to come up with mechanic for junctions without traffic lights... that needs to be a bit more advanced... and right now im not 100% sure how i would implement that

and then i also dont know how i would handle lane changing... for example on highway, cars would randomly change lane, so that would probably switch to other iTween somehow? not sure :/

im also looking at some waypoint systems on asset store right now, or some pathing systems... so yeh im open to any ideas basically, i want to do this well... it doesnt have to be super realistic, but i want it to be better than what other competitors on android market have right now... and they have quite bad implementations of AI traffic...

edit: well i think i am on right path with using iTween, since i found this little iTween editor, and it has vehicles following iTween paths in there: https://www.assetstore.unity3d.com/#/content/9455

also found this one: https://www.assetstore.unity3d.com/#/content/2506

but those are just path solutions... i still need to design logic for junctions
« Last Edit: December 23, 2013, 05:00:17 AM by bizilux »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Need help with making Realistic AI Traffic Behavior
« Reply #1 on: December 26, 2013, 02:17:17 AM »
Hi,

 Your best approach to design the logic is to use PlayMaker. PlayMaker will be very powerful to create traffic AI logic.

Your explanation of how you tackle this seems very good. Don't over think road cross, it's actually not difficult, have wider triggers to detect cars from far and they will act as "warnings" for cars willing to cross ( you need one collider per road, not one big collider for both roads crossing, so that on on road you can query for coming cars, and on your own road you can query for cars coming towards you but willing to turn and cross the road).


Have you contacted Edy and mention your case? he may have experimented or actually worked on a AI car with his system.

First make your ai with just traffic light, and see how far you can take it, then you'll tackle other cars management and checks.

bye,

 Jean


bizilux

  • Full Member
  • ***
  • Posts: 171
Re: Need help with making Realistic AI Traffic Behavior
« Reply #2 on: December 26, 2013, 07:45:19 AM »
thanks jean,

yes i think junctions could actually be doable with just triggers, and then just writing the logic of what happens when these triggers are triggered

basically 1 trigger per lane, so if i had normal junction with 4 directions... i would have 8 triggers...  basically each lane would have one trigger before junction starts, and after it ends, so that it detects when the car crossed junction, so that the next car can go...  right now, this sounds like the best idea in my head

if that will be too hard to do, then i will just use junctions with traffic lights, haha :D


and i think i will only send 1 raycast out from car... just 1 ray from front of the car, 2 meters range, something like that... i think just 1 ray is fine...

i might need to put more rays into the car if they will have switching lanes mechanics... but those sideway rays will only be turned on if the car will actually want to switch lanes, otherwise they would be off.


for cars movement, i will probably just use translate function... just something that moves cars along iTween paths... it might look a bit weird with corners, since that is not how cars behave in corners. (they steer with front 2 tires, and dont pivot around center like tanks do)... but i think it will look fine for mobile use...


problem with using edy's physics for AI, is that it doesnt scale very well... for 1 car it is ok, but when you add 20+ cars there it cripples phones fps
you can check here in the end of the video:

ur right, first i will do junctions with traffic lights, since that is the easiest, and get the movement on itween paths correctly, and then go into junctions without traffic lights... i will try to do all that in next couple of days, and  i'll report back :)

-----------

in the end... it just comes down to proper logic behind it... if you have the proper logic in ur head, then its quite easy to do it with playmaker...

yesterday, i was doing breaking velocity mechanic, it basically checks if bus has been breaking for too long, that means that the driver is breaking too hard, so passengers will be unhappy with that much breaking...

so i have a float variable from 0-100, and the longer you hold break button, the higher that value goes, and once you release break button, it quickly goes down to 0 again... so its basically "velocity meter" ...  oh boy i have been solving that one for 2 hours... trying all different complex things, cracking my head with it, almost giving up... and then i solved it with most simplified thing ever...   
float add action, and wait action.   so when you are holding break button, every 0.1 seconds, it adds +3 to float variable... and that fills up velocity meter, and once you release it, it subtracts 10 velocity every 0.1 seconds...

just so simple thing to do... if i only had the right logic at the beginning...
« Last Edit: December 26, 2013, 07:59:25 AM by bizilux »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Need help with making Realistic AI Traffic Behavior
« Reply #3 on: December 26, 2013, 08:24:13 AM »
Hi,

 Keep it up, this is the way to learn!

bye,

 Jean

bizilux

  • Full Member
  • ***
  • Posts: 171
Re: Need help with making Realistic AI Traffic Behavior
« Reply #4 on: December 26, 2013, 08:45:35 AM »
hm... possibly found limitation to itween...

one review for itween... :/
Quote
"Really easy to use, but uses too much HW resources(1 of 1 found this review helpful)
by George Rigato, 16 Nov 2013
When I started using iTween it really saved a lot of dev time because it is REALLY EASY to use. But when I realised that it was causing massive FPS drop on mobile (iPhone 4) I had to redo a lot of movement code.

Now I know it's limitations, my advice will go to use it on routines that don't run constantly and repeatedly (and if your game will be deployed on low specs hardware)."

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Need help with making Realistic AI Traffic Behavior
« Reply #5 on: December 26, 2013, 09:14:56 AM »
Hi,

 yes, this is a know  limitation with iTween.

 Prefer hotween or leantween for example.

bye,

 Jean

bizilux

  • Full Member
  • ***
  • Posts: 171
Re: Need help with making Realistic AI Traffic Behavior
« Reply #6 on: December 26, 2013, 09:54:25 AM »
i've looked into leantween, and it seems to be the best, but there arent playmaker actions for it, so i'll just have to use hotween... but thats okey, since i wont be having that many cars in scene, so that will work just fine...

if only i will be able to figure out how to use hotween :D


well im thinking of buying  Simple Waypoint System
https://www.assetstore.unity3d.com/#/content/2506

since it has some waypoints to make a path... this seems to lack with hotween... sure i can add vector 3 coordinates of where i want the car to go...  but i dont know, just seems way more work than what i could do with itween... if i remember correctly, itween lets you draw paths...   havent found this with hotween
« Last Edit: December 26, 2013, 10:27:17 AM by bizilux »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Need help with making Realistic AI Traffic Behavior
« Reply #7 on: December 27, 2013, 02:30:12 AM »
Hi,

 Simple Way point seems a better option for sure.

bye,

 Jean