Question by
Abotics99 · Jan 20, 2016 at 01:49 AM ·
c#camera-movementlookatcamera-looksecurity
Security Camera Robotic Movement
I'm trying to recreate the movement of the security cameras in the Portal games. If you somehow haven't played, the cameras will slowly catch up to looking directly at you. I would like the camera to move at a constant speed without any kind of lerping. Right now my script for it is just the lookat command but it is just too fast and doesn't look realistic. Thanks for any help I can get!
Comment
Answer by incorrect · Jan 20, 2016 at 02:09 AM
using UnityEngine;
using System.Collections;
public class CameraRotation : MonoBehaviour
{
[SerializeField]
private Transform target;
[SerializeField]
private float rotationSpeed = 1f;
void CameraLook()
{
//Rotates looking direction in the direction of a target at a given speed
Vector3 lookDirection = Vector3.RotateTowards(transform.forward, target.position - transform.position, Mathf.Deg2Rad * rotationSpeed, 0f);
//Calculate point to look based on lookDirection we got abowe
Vector3 lookPoint = transform.position + lookDirection;
//Using LookAt() to prevent camera tilting
transform.LookAt(lookPoint);
}
void Update ()
{
CameraLook();
}
}
Ask your questions if you have any.
Your answer
Follow this Question
Related Questions
Camera Jitters When Displacing and Rotating Smoothly 0 Answers
Make Camera follow rotation of 2 Players 1 Answer
My camera rotate but my player dont. How Ive to do so? 1 Answer
Sit Down First person 0 Answers
Smooth camera movement by mouse 0 Answers