Ok, using the 2D tutorial, I was able to sort of set up a camera that I want, but I am missing some parameters. I know what I want to happen, any hints would be great.
2D View so the ship will fly only on the z axis.
The camera view is actually the border for the ship, so while the ship can move around freely up, down, left, right, it cannot leave the bounds of the view of the camera. The camera is locked to it, but the ship can go past the center of the camera view.
The ship and camera need to be constantly moving through the level, say starting at one end of the terrain and to the other on the z axis. Then the ship can move within it.
I am a bit of a scripting noob, but I do understand the concepts and calls of JavaScript
Firstly, you should parent the ship to the camera so that whenever the camera moves, the ship moves by the same amount. Then, you can use a script like the following to calculate where the edges of the view are (in camera space) and keep the ship within them:-
var shipSpeed: float;
var shipDistance: float;
private var cam: Camera;
private var ship: Transform;
private var maxX: float;
private var maxY: float;
function Start() {
cam = GetComponent(Camera);
ship = transform.Find("Ship");
// Find the coordinates of the edge of the view in camera space.
maxY = shipDistance * Mathf.Tan(Mathf.Deg2Rad * cam.fieldOfView * 0.5);
maxX = maxY * cam.aspect;
}
function Update () {
var xMove = Input.GetAxis("Horizontal") * shipSpeed * Time.deltaTime;
var yMove = Input.GetAxis("Vertical") * shipSpeed * Time.deltaTime;
ship.localPosition.x = Mathf.Clamp(ship.localPosition.x + xMove, -maxX, maxX);
ship.localPosition.y = Mathf.Clamp(ship.localPosition.y + yMove, -maxY, maxY);
ship.localPosition.z = shipDistance;
}