# Orbit/Rotate camera through four set positions

I made a simply follow script with a switch to change the position of the camera to any of those four positions but I don’t like the result, now I want to make a rotate/Orbit the camera through these four positions, think of this four positions as South, west, east and north of the orbit camera, The regular orbit camera don’t suit my needs.

To illustrate the difference I made a comparison image, both camera script have the same angle (45º) and roughly the same distance, yet the orbit camera offers zero visibility in comparison.

This is my script as of now, those four positions are in the cases I use to change between them, I want to turn this into and orbit camera

``````using UnityEngine;
using System.Collections;

public class cameraFollow : MonoBehaviour {
public GameObject doke;
public Vector3 rotationoffset;
public float offset;
public float height;
private int procams = 0;

// Use this for initialization

void Start () {

}

// Update is called once per frame
void LateUpdate () {
if (Input.GetButtonDown("Fire2") == true){
procams += 1;
}
switch (procams){
case 4:
procams = 0;
break;
case 3:
//westest position
transform.position = new Vector3 (doke.transform.position.x +offset, doke.transform.position.y + height,doke.transform.position.z );
transform.localEulerAngles = new Vector3 (rotationoffset.x , 270,rotationoffset.z);
break;
case 2:
//norhtest position
transform.position = new Vector3 (doke.transform.position.x , doke.transform.position.y + height,doke.transform.position.z +offset);
transform.localEulerAngles = new Vector3 (rotationoffset.x , 180,rotationoffset.z);
break;
case 1:
//eastest position
transform.position = new Vector3 (doke.transform.position.x -offset, doke.transform.position.y + height,doke.transform.position.z );
transform.localEulerAngles = new Vector3 (rotationoffset.x , 90,rotationoffset.z);
break;
case 0:
//southest position
transform.position = new Vector3 (doke.transform.position.x , doke.transform.position.y + height,doke.transform.position.z -offset);
transform.localEulerAngles = rotationoffset;
break;
}
}
}
``````

If you are thinking I could just add offset (like my cam does) to the orbit camera I already tried that, didn’t work, the orbit center was displaced.

Ok, I actually forgot about the follow script and wrote an orbit camera script from scratch to include an Offset value, here it is in case anyone interested

``````public Transform target;
public float distance = 10.0f;
public float offsetpos = 0.0f;
public float xSpeed = 250.0f;
public float ySpeed = 120.0f;

public float yMinLimit = -20;
public float yMaxLimit = 80;

private float x = 0.0f;
private float y = 0.0f;

void Start ()
{
var angles = transform.eulerAngles;
x = angles.y;
y = angles.x;

// Make the rigid body not change rotation
if (rigidbody)
rigidbody.freezeRotation = true;
}

void LateUpdate ()
{
if (target)
{
x += Input.GetAxis("Mouse X") * xSpeed * Time.deltaTime;
y -= Input.GetAxis("Mouse Y") * ySpeed * Time.deltaTime;

y = ClampAngle(y, yMinLimit, yMaxLimit);

transform.rotation = Quaternion.Euler(y, x, 0);
//transform.position = new Vector3 (x , height, distance);
transform.position = (Quaternion.Euler(y+offsetpos, x, 0)) * new Vector3(0.0f, 0.0f, -distance) + new Vector3(target.position.x, target.position.y, target.position.z);
}
}

static float ClampAngle(float angle, float min, float max)
{
if (angle < -360)
{
angle += 360;
}
if (angle > 360)
{
angle -= 360;
}
return Mathf.Clamp(angle, min, max);
}
``````

}

Could you just make 4 camera game objects, all children of the Player, and only one set ‘active’ at a time?