Hi Guys
First im best letting you know I do not have any experience with coding, however I have had a play around with Unity for about a month and I have watched a few youtube vids.
Ok now my problem:
im trying to setup a virtual traffic system. I have managed to setup a waypoint system with 2 cars. My problem is getting them to detect and stop if 1 of them enters the others path e.g. turning into a road. I have made a box as a collider and scripted a basic stop start on enter/exit. however the script does not work if both cars have the script attached?? Here is my code in java:
function OnCollisionEnter (Car : Collision){
if (Car.gameObject.name == “AI1”){
rigidbody.isKinematic = true;
function OnCollisionExit (Car : Collision){
if (Car.gameObject.name == “AI1”){
rigidbody.isKinematic = false;
}
No idea if im completely doing this wrong but any guidance or even some help creating this script would be great 
Spuddage,
Are these cars on regular streets? Do they “obey the rules of the road” - like stopping at stop signs and traffic lights? If so, it would probably be easier to make the the cars obey the rules of the road and have the road tell the car what it’s allowed to do.
Eg. A stoplight at an intersection might let cars traveling one way go while car traveling another way stop.
yes I want them to obey the rules of the road but I have no idea how to do that. I like the idea of the road doing the work but my current road is basically Terrain with texture on it.
Edit:
I could do with a basic trigger so that if the main car comes into contact with the other cars box(collider) then the other car will stop. as soon as its passed the car can go again. thereby any car that is following another will stop if the car infront does. I will sort out the traffic lights later but I was thinking of using a timed trigger???
Colliders are “expensive” - so if you are going to have more than a few cars, having the road do the work is better (no possible collisions). It’s also just a better way to architect it in general.
I would create a “RoadSegment” class and for each segment of road apply one of these to it. Each road segment would know about the attachment points to the road segments and each road attachment point could control what traffic pattern is allowed through it at any given time. Each car would know what road segment it was on and what road segment it was trying to get to, with these two pieces of info, it could communicate with the intersection object and be told what it’s allowed or supposed to do.
You are trying to solve a very complicated problem. I am doing something similar for my next game, and it’s taken 3-4 months to get it in a state that looks like it’s working.
Yep i get where your coming from but i am trying to keep it basic. I’ll only be using 5 - 10 cars for now. Iv got a trigger to stop the car but I cant set it as the box infront of the car. atm its working on the parent making the car stop when any part comes into contact. this making both cars stop.
what im trying to do is set the trigger to my box Object so when the box is triggered the car stops that way the other car shouldnt stop??
var left : ActivateTrigger;
function OnTriggerEnter () {
rigidbody.isKinematic = true;
}
function OnTriggerExit (other : Collider) {
rigidbody.isKinematic = false;
}