Hello, I'm trying to make a simple car, in a city, to randomly choose to go left or right at each intersection it passes, I'm using triggers at the intersections. Here's the script for the car -
//Triggers will access the turnNow variable.
var turnNow = false;
var speed = 5.0;
var turnSpeed = 2.0;
private var chance;
private var goLeft = false;
private var goRight = false;
function Update ()
{
//Drive!
transform.Translate(0,0,speed * Time.deltaTime);
chance = Random.Range(0,100);
if(turnNow)
{
if(chance>50)
{
//go left!
goLeft = true;
}
else
{
//go right!
goRight = false;
}
}
if(goLeft)
{
//go left!
iTween.RotateTo(gameObject,{"y":transform.rotation.y-90,"time":turnSpeed});
}
if(goRight)
{
//go right!
iTween.RotateTo(gameObject,{"y":transform.rotation.y+90,"time":turnSpeed});
}
}
and the trigger script, even though I think the car script is the problem -
function OnTriggerEnter (collider : Collider)
{
collider.GetComponent("CarMapper").turnNow = true;
}
function OnTriggerExit (collider : Collider)
{
collider.GetComponent("CarMapper").turnNow = false;
}
and the problem is that when the car passes the trigger, turnNow isn't changed. How can I fix this?
O hai ther! I fixed some of your indentation and formatting.
– StatementSomehow Statement you manage to crack me up. :)
– FLASHDENMARK