Hello everyone, I am making a game where you have 3 lanes that you can move around , a left one, a middle one and a right one, I managed to make this code here :
var veloc : float = 5;
var porco : GameObject;
var faixa1 : GameObject;
var faixa2 : GameObject;
var faixa3 : GameObject;
var faixaAtual : int = 0;
//-1 -> Esquerda 0 -> Meio 1 -> Direita
function Update(){
transform.Translate(Vector3.forward * veloc / 2);
if(faixaAtual > -2 && faixaAtual < 2){
if(faixaAtual == -1){
if(Input.GetKeyDown(KeyCode.RightArrow)){
faixaAtual = 0;
porco.transform.position = Vector3(faixa2.transform.position.x,
2.5, porco.transform.position.z);
}
}
if(faixaAtual == 0){
if(Input.GetKeyDown(KeyCode.LeftArrow)){
faixaAtual = -1;
porco.transform.position = Vector3(faixa1.transform.position.x,
2.5, porco.transform.position.z);
}
if(Input.GetKeyDown(KeyCode.RightArrow)){
faixaAtual = 1;
porco.transform.position = Vector3(faixa3.transform.position.x,
2.5, porco.transform.position.z);
}
}
if(faixaAtual == 1){
if(Input.GetKeyDown(KeyCode.LeftArrow)){
faixaAtual = 0;
porco.transform.position = Vector3(faixa2.transform.position.x,
2.5, porco.transform.position.z);
}
}
}
}
but when I am moving between the “-1” lane to the “0” lane, the character skips to the “1” lane, and I can’t figure out how to fix it! Any help would be appreciated!
observation: I’m brazillian , and my variables are in portuguese, so here is a tradution of the variables : (faixa = lane) (veloc = speed) (porco = pig) (faixaAtual = currentLane).