- Home /
3D "Frogger" traffic respawning incorrectly
In my game, I have a row of cars driving down a road (one is a sedan, one is a jeep.) Each car has an empty parent in the center of it with a rigidbody attached and this script:
var dir : Vector3;
var speed : float;
function Update(){
transform.position += dir.normalized * speed * Time.deltaTime;
}
function OnTriggerEnter(other : Collider){
if(other.tag == "CarEndpointRight"){
transform.position = Vector3(-27, transform.position.y, transform.position.z);
}
}
Each car is spaced 8m apart. The x position, "-27" is the location of the last car in the line before the traffic starts moving. My problem is, even though I believe I have the number set correctly, each time the cars respawn by entering my "traffic endpoint" with a box collider trigger, the gap between the sedan and the jeep gets smaller and smaller, until they're bumper to bumper. Obviously, this won't do in a game similar to Frogger.
I should also mention the car is changed from sedan, to jeep, to sedan, etc. for every other car. What am I doing wrong?
Your answer
Follow this Question
Related Questions
Error says object reference not set when it really is? 1 Answer
[solved] Having a problem with respawning script. the player didn't go to the proper respawn point 1 Answer
tranform.position always leads to 0, 0 1 Answer
Script error: respawn upon collission 2 Answers
Distance Between NavMeshAgent and RaycastHit,Distance between NavMeshAgent and RayCastHit 1 Answer