Having Fun With the Camera (part 2)
At this point, we have the code ready to flip the camera movement back and forth. But we don't have any code to regularly 'time' this flipping at set intervals. This is where we need another if(condition)-type statement to check whether or not it is time to flip the camera going the opposite direction. There are 2 ways of doing this. We could make an artificial clock timer and at set times, flip the switch. We might see this timer element later in our games, but for now I want to try the other easier option. All we will do is set a distance limit that our camera can travel. Once it reaches this limit, we stop the camera, flip the switch, and send it in the opposite direction. Here's the new 'if' statement that we will add: if(camera.position.z > 10){ camera.position.z = 10; forwardFlag = true; } Remember that when our program starts, the forwardFlag is set to 'false' and therefore the camera is constantly moving backwards wi...