I am sure this is not what you want. The best I can see is that you are trying to mimic a Mouse Orbit and damping it.
To get SmoothDampAngle to work at all, I had to revert back to the documentation:
using UnityEngine;
using System.Collections;
public class MyCamera : MonoBehaviour
{
public Transform target;
public float smooth = 0.3F;
public float distance = 5.0F;
private float xVelocity = 0.0F;
private float yVelocity = 0.0F;
void Start(){
Vector3 position = target.position;
position += Quaternion.Euler(0, 0, 0) * new Vector3(0, 0, -distance);
transform.position = position;
}
void Update() {
if(Input.GetMouseButton(0)){
float xAngle = Mathf.SmoothDampAngle(transform.eulerAngles.x, target.eulerAngles.x, ref xVelocity, smooth);
float yAngle = Mathf.SmoothDampAngle(transform.eulerAngles.y, target.eulerAngles.y, ref yVelocity, smooth);
Vector3 position = target.position;
position += Quaternion.Euler(xAngle, yAngle, 0) * new Vector3(0, 0, -distance);
transform.position = position;
transform.LookAt(target);
} else {
xVelocity = 0.0F;
yVelocity = 0.0F;
}
}
}
This by its self does not move the camera, but more centers it behind an object. This peice of code I did for someone on the forum here and it will rotate and object.
var timeScale=1;
function Update () {
LookAround();
timeScale=1;
if(Input.GetKey("space")) timeScale=0.2;
Time.timeScale=Mathf.Lerp(Time.timeScale, timeScale, 4 * Time.deltaTime);
}
function LookAround() {
var x = Input.GetAxis ("Mouse X");
var y = -Input.GetAxis ("Mouse Y");
transform.Rotate (y * 4, x * 4, 0);
//x=transform.localEulerAngles.y;
//if(x>180) x-=360;
//x=Mathf.Clamp(x, -80, 80);
//transform.localEulerAngles.y=x;
transform.localEulerAngles.z=0;
}
Now, having a look at the concept from a MouseOrbit standpoint… I believe changes to it will help alot more than working on it in this state:
var target : Transform;
var distance = 10.0;
var useMouse=true;
var damping=4.0;
var xSpeed = 250.0;
var ySpeed = 120.0;
var yMinLimit = -20;
var yMaxLimit = 80;
private var x = 0.0;
private var y = 0.0;
private var targetPosition : Vector3=Vector3.zero;
function Start () {
var angles = transform.eulerAngles;
x = angles.y;
y = angles.x;
// Make the rigid body not change rotation
if (rigidbody)
rigidbody.freezeRotation = true;
if(!target)targetPosition=transform.position;
}
function LateUpdate () {
var targ=targetPosition;
if (target) targ=target.position;
if(Input.GetMouseButton(0) || !useMouse){
x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
y = ClampAngle(y, yMinLimit, yMaxLimit);
}
var rotation = Quaternion.Euler(y, x, 0);
rotation=Quaternion.Slerp(transform.rotation, rotation, damping * Time.deltaTime);
var position = rotation * Vector3(0.0, 0.0, -distance) + targ;
transform.rotation = rotation;
transform.position = position;
}
static function ClampAngle (angle : float, min : float, max : float) {
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp (angle, min, max);
}
Hope it helps