Is there a standard way to align the camera to always have one edge of a target object start at the bottom/top of a screen?

what I’m about to say is just guesswork, so if I’m wrong somewhere please point it out to me. The field of view you set on your camera is the width of the camera’s view angle along the local y axis. The height is then dependent on your screen resolution and your field of view.

So if you know your field of view *and* you know your screen resolution *and* you know the distance from the camera to the object you want to align the camera with (if you don’t, use raycasting) I suppose it’s simple trig to figure out how high the camera should be for the top/bottom of the bounding box of that object to aling with the top/bottom of the frustum of your camera.

I just wrote this script that moves my camera so that the 0,0 game position is the lower left of the camera’s visible bounds, and the upper right location can be retrieved from getGameBoardSize();

So, if you wanted to move an object to the left side of the screen you would just set it’s X position to 0. Right side = getGameBoardSize().x

Same for top and bottom: bottom = 0, top = getGameBoardSize().y

I literally just wrote this tonight for my project so it’s not tested 100% but it seems to work so far.

https://gist.github.com/5c20699bde0524acf9ac

```
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Camera))]
public class AlignedCamera : MonoBehaviour {
protected Vector2 m_gameBoard;
// Use this for initialization
void Start () {
// get the vertical FOV from the camera
// divide by 2 since the triangle we're solving is half the actual FOV triangle
float vFov = camera.fieldOfView / 2f;
// get the distance from the camera to the game board
float cameraDistance = Mathf.Abs(transform.position.z);
// calculate the 3rd angle of our right angle triangle
float lastAngle = 180f - 90f - vFov;
// now we have 2 sides to our triangle, we need the 3rd side (the game board height)
// solve via law of sines
// multiply by 2 because this is only half the actual FOV triangle
float vSize = ( (Mathf.Sin(vFov * Mathf.Deg2Rad) * cameraDistance) / Mathf.Sin(lastAngle * Mathf.Deg2Rad) ) * 2f;
// now calculate the hSize by a simple ratio equation
float hSize = (Screen.width * vSize) / Screen.height;
// move the camera to be half that so our bottem left point is 0,0
transform.position = new Vector3(hSize/2f, vSize/2f, transform.position.z);
Debug.Log ("resolution(" + Screen.width + " x " + Screen.height + ") gameBoard(" + hSize + " x " + vSize + ")");
m_gameBoard = new Vector2(hSize, vSize);
}
public Vector2 getGameBoardSize() {
return m_gameBoard;
}
// // Update is called once per frame
// void Update () {
//
// }
}
```