I have a game object placed at the position (0, 5, 80)
I want that this object ciclically moves foward (direction x in my orientation) and then when has reached a certain position turn back until has reached another limit position and so on .
It’s a very simple task but unfortunately when the object reaches the stop to move and desn’t change direction.
function cyclicMove(){
if(boat.position.x <= -190){
boat.rotation.y=-90;
}
else if(boat.position.x >= 190){
boat.rotation.y=90;
}
else if(boat.position.x > -190){
boat.position.x–;
}
else if(boat.position.x < 190){
boat.position.x++;
}
}
It should do the trick. Be careful though that the last else if is not reached if you have for example boat.position.x = 0