Rotate a camera around an Object

Alright, first off, here is the desired result :
http://www.grayboxgames.com/GBG/Tests/GrabNRotate.html

The only problem being that the camera needs to be the object that rotates, not the central model.

Also, would it be possible to tell me what you would call that type of orbit? I was searching it for about an hour and couldn’t find anything :smiley:

This is a copy of my answer here : Simple Object Rotate - Questions & Answers - Unity Discussions

Do you mean for the planet to travel along a path that rotates around the sun, or for the planet to spin on it’s own axis?

In a new scene, create a cube, position it at (5,0,0), attach this script :

var PlanetRotateSpeed : float = -25.0;
var OrbitSpeed : float = 10.0;

function Update() {
    // planet to spin on it's own axis
    transform.Rotate(transform.up * PlanetRotateSpeed * Time.deltaTime);
    
    // planet to travel along a path that rotates around the sun
    transform.RotateAround (Vector3.zero, Vector3.up, OrbitSpeed * Time.deltaTime);
}

I Imagine you could use a combination of Transform.Rotate and LookAt to have the camera rotate around the object while the camera looks at the object (to save doing rotation calculations).

public Transform TargetLookAt; //target to which camera will look always
public float Distance=20f; //distance of camera from target

	public float DistanceSmooth=0.05f;	//smoothing factor for camera movement
	public float X_Smooth=0.05f;
	public float Y_Smooth=0.1f;
	public float height=35f;
	private float rotX=0f;		
	
	private float speed=80f;
	private float desiredDistance=0f; //desired distance of camera from target
	private float velDistance=0f;	
	private Vector3 desiredPosition=Vector3.zero; 
	private float velX=0f;
	private float velY=0f;
	private float velZ=0f;
	private Vector3 position=Vector3.zero;
	
	
	void LateUpdate () 
	{
		if(TargetLookAt==null)
			return;
		AngleCalc();
		CalculateDesiredPosition();
		UpdatePosition();
	}
	
		
	void AngleCalc()
	{
		
		rotX+=Time.deltaTime*speed;
		
	}
	
	void CalculateDesiredPosition()
	{
		desiredPosition=CalculatePosition(height,rotX,Distance);
	}
	
	Vector3 CalculatePosition(float rotationX, float rotationY, float distance)
	{
		Vector3 direction=new Vector3(0,0,-distance);
		Quaternion rotation=Quaternion.Euler(rotationX,rotationY,0);
		return TargetLookAt.position+rotation*direction;
	}
	
	void UpdatePosition()
	{
		var posX=Mathf.SmoothDamp(position.x,desiredPosition.x,ref velX,X_Smooth);
		var posY=Mathf.SmoothDamp(position.y,desiredPosition.y,ref velY,Y_Smooth);
		var posZ=Mathf.SmoothDamp(position.z,desiredPosition.z,ref velZ,X_Smooth);
		
		position=new Vector3(posX,posY,posZ);
		transform.position=position;
		transform.LookAt(TargetLookAt);
	}

Check if this script works for you…