What's the best approach to moving cameras through a level?

Ahoy! Game is a top-down endless runner, basically.

The camera should constantly be moving along with the player (though not attached TO the player – it’s the player’s job to stay within the camera). The level does have changes in height/y-axis.

What’s the best way to move the camera along, accounting for height changes and such? Right now I’m basically using this code:

public class CameraMovement : MonoBehaviour 
{
	public Transform target;
	public float smooth = 2;

	private Vector3 newPosition;	
	
	void PositionChanging()
	{
		transform.position = Vector3.MoveTowards(transform.position, newPosition, Time.deltaTime * smooth);
		
	}	
	
	void Start()
	{
		newPosition += new Vector3(15,0,0);
	}
	
	void Awake()
	{
		newPosition = transform.position;	
	}
	
	// Update is called once per frame
	void Update () 
	{
		PositionChanging();
		
	}
}

This is fine right now as I’m getting started, as it starts the camera moving in the proper direction, to a spot I’ve assigned. But now that it reached that position… what now? :slight_smile: How do I get it to go from there to another position? Or is there another way I should be thinking about this?

As a starting point you are looking for some sort of path following or waypoint system. There are a bizillion posts on waypoints, including some code that follows waypoints.

But to start I would suggest you use iTween. You can download it free from the Asset store. In addition there is a path editor for creating your path:

http://pixelplacement.com/2010/12/03/visual-editor-for-itween-motion-paths/

If you are going to experiment with iTween, given the few details of your game here, I’d use iTween.PutOnPath() with an empty game object. Make the camera a child of the empty game object. That way you can use localPosition.y camera/child to move the camera up and down to match the player while still staying on the path.

Awesome, thanks for the tip and will check it out.