- Home /
Question by
Kraz_Mason · Mar 12, 2017 at 06:12 PM ·
unity 5
Hey, I am trying to make the Main Camera rotate around an object but I keep on getting errors left and right and I don't know what to fix or do. Can you please look at my code and tell me what I need to do to fix this?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class ThirdpersonCamera : MonoBehaviour { private const float Y_ANGLE_MIN = 0.0f; private const float Y_ANGLE_MAX = 50.0f;
public Transform lookAt;
public Transform camTransform;
private ThirdpersonCamera cam;
private float distance = 10.0f;
private float currentX = 0.0f;
private float currentY = 0.0f;
private float sensivityX = 4.0f;
private float sensivityY = 1.0f;
private void Start()
{
camTransform = transform;
cam = Camera.main;
}
private void Update()
{
currentX += Input.GetAxis("Mouse X");
currentY += Input.GetAxis("Mouse Y");
currentY = Mathf.Clamp(currentY, Y_ANGLE_MIN, Y_ANGLE_MAX);
}
private void LateUpdate()
{
Vector3 dir = new Vector3(0,0,-distance);
Quaternion rotation = Quaternion.Euler(currentY,currentX,0);
camTransform.position = lookAt.position + rotation * dir;
camTransform.LookAt(lookAt.position);
}
}
Comment
I got this code from a Youtube tutorial. https://www.youtube.com/watch?v=Ta7v27yyS$$anonymous$$s&t=16s That is the link to the video.
Your answer
Follow this Question
Related Questions
How do i create points along a spline??? 0 Answers
Two instances of Unity3D 5 0 Answers
Button Enabling/Disabling using Collision Triggers? 1 Answer
Using Raycasts 0 Answers