Unity for development of driving simulator

Hello there, I have started using unity for developing a driving simulator with a motion platform…Just starting this thread to log my progress n ask for scripting advices…:smile:.

Given that unity already has a lot of features ready to use…hope this will be easy…

My progress: So far i have implemented the basic movement of our car and ai cars via waypoints…n now i need some ideas for the following:

  1. I need to implement a signal system wherein cars (AI) stop at red lights…my first idea was that at a red light i will put up a collider(invisible wall) on the road, the ai cars will cast a ray n detect the collider n then stop…after implementing it i realised that even if the ai cars stop…if our car continues to move ahead it will collide with the invisible collider…this is where i need some ideas…

  2. Basically the simulator is for learning purposes…i will need to identify basic faults such as lane crossing etc. we used to achieve this by giving individual road nos to lanes…prob is i cant give all roads individual colliders…(about 100-150 road nos) for road detection…any ideas here…i am thinking of just using an extra mesh which will be the white line for detecting lane change errors…

Hello, Make your collider a trigger. Then when entered the car’s AI can check if the light is red or not. On the trigger you could use a static bool, and control that bool from your light. Then wala, light turns red, flips the static bool, car enters the trigger and stops. You can gain control of the car or cars that enter the trigger by tag name. Hope this helps.

oooh…thanks a lot…should have used the scripting reference…:stuck_out_tongue:
“A trigger doesn’t collide with rigid bodies. Instead it sends OnTriggerEnter, OnTriggerExit and OnTriggerStay message when a rigidbody enters or exits the trigger”
…that takes care of the first problem

You can also use a way point system, which would be better IMO then trigger boxes. Attach a script to each way point that tells the vehicle what it is, and what it is connected to.

Think of it this way:

vehicle is driving from last way point to the next way point(non red light).
it gets to the way point then asks, where do I need to go. Since it is traveling in direction A, it has to choose a direction A or B(if one is connected to it)
direction A, since there is no direction B
the vehicle then assigns it’s target as target A and asks what target A is. It’s a red light and it’s current state is green.
The vehicle drives along to way point A, suddenly it turns yellow. We can estimate it’s time to turn red instead of knowing by adding a Random.value to 1 second or so.
Now we make a choice, velocity / distance. Enough room, slow down, not enough, Oh yeah you got it, what we all do… speed up.
Say he slows down by the time he reaches the light and stops.
now, he is at target A, time to choose a new target A, B or C.
A and B you have to wait until the light turns green for, C you do not.

The whole way through the sequence, the vehicle has to know what other vehicles are around them and what they are doing. You can also put in other behavioral variables and how they would affect the choices of where he is going or how he reacts to other drivers.

In your way points you can put distance to the next way point, then use something like an A* AI to calculate where someone is going and what is the best route to get there.