I’m currently trying to figure out the code for a part of the game I am working on. The idea is you have a car (represented by the Red Block) dodging oncoming traffic (represented by the 1,2,3 blocks) automatically by switching lanes. For example, if the Red block is in lane 1 then it’ll either move to lane 2 or 3 (See second image). To have it move smoothly from one lane to another I have the Red Block “lerping” from one lane to another. The problem I am having is making sure the block moves to the correct lane when a car is incoming so as to not hit the oncoming car.
The system I have in place right now uses global variables. So any combination of the traffic spawning has an associated global variable. For example, every 3 to 5 seconds the system chooses a variable (2,4,6,8,10,12). I call the variable "Lane Check" in the image below. If it chooses a 10 then the launchers will shoot a 1 Block and 3 Block. Since the variable equals 10 then the Red Block knows to stay in lane 2 to avoid the 1 Block and 3 Block.
This system sort of works, but it needs the kinks worked out of it or I need to do something completely different. This is where I need help. So if there is any way somebody could help me out that would be awesome. I’ve been fighting with this for while trying all kinds of things. I’ve attached a link to the .c3p file to provide further insight into my problem and give a better understanding. Thanks!
https://www.dropbox.com/s/6geqdzs9ndpqjgs/Automatic%20Lane%20Change.c3p?dl=0