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? How do I get it to go from there to another position? Or is there another way I should be thinking about this?