Question by
Patrick96kelly · Apr 04, 2016 at 05:59 PM ·
cameracontroller
Camera controller help
Hey all, I have to do a games assignment where you play as a robot. I am trying to have it so the camera follows the robot as it moves around and the camera is positioned behind the robot. While I have the camera done, I have the problem where the camera is just on constant rotate around the model. It doesn't stop and just keeps moving quickly around the model in a circular motion. I feel this can easily be changed but I don't know how. Anyone have an idea how to fix this? Here is my code for the camera:
using UnityEngine;
using System.Collections;
public class FollowCamera : MonoBehaviour
{
public GameObject target;
public float damping = 3;
Vector3 offset;
void Start()
{
offset = target.transform.position - transform.position;
}
void LateUpdate()
{
float currentAngle = transform.eulerAngles.y;
float desiredAngle = target.transform.eulerAngles.y;
float angle = Mathf.LerpAngle(currentAngle, desiredAngle, Time.deltaTime * damping);
Quaternion rotation = Quaternion.Euler(0, angle, 0);
transform.position = target.transform.position - (rotation * offset);
transform.LookAt(target.transform);
}
}
Thanks and sorry if I am not fully explaining it.
Comment