Question by
eirikamb · Jul 03, 2016 at 12:20 PM ·
c#camera rotateglitchthird-person
Why does my camera rotate on the x axis because of this script? What is wrong with the script?
This script should rotate the camera on the x axis.. The target is the tps player, but the camera rotates on the x axis whenI test my game and the rotation is too big so you dont see much more than the charater... Please help, I appreciate it.. Thanks!
using UnityEngine; using System.Collections;
public class CameraRotation : MonoBehaviour { [SerializeField] private Transform target;
public float rotSpeed = 1.5f;
public float _rotY;
private Vector3 _offset;
// Use this for initialization
void Start () {
_rotY = transform.eulerAngles.y;
_offset = target.position - transform.position;
}
// Update is called once per frame
void LateUpdate () {
float horInput = Input.GetAxis("Horizontal");
if (horInput != 0)
{
_rotY += horInput * rotSpeed;
}
else
{
_rotY += Input.GetAxis("Mouse X") * rotSpeed * 3;
}
Quaternion rotation = Quaternion.Euler(0, _rotY, 0);
transform.position = target.position - (rotation * _offset);
transform.LookAt(target);
}
}
Comment
Your answer
Follow this Question
Related Questions
How to stop the character from rotating around? 1 Answer
Coroutines stop randomly (Unity glitch) 0 Answers
Third Person Camera Roatates Diaginal 0 Answers
Help rotating camera script 0 Answers
uNet FPS Camera Error [C#] [Unity 5] 2 Answers