I’m trying to make a third person camera but when rotating the z axis it makes it look weird and i don’t know how to make it not rotate the z axis here’s my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
private GameObject player;
private GameObject cam;
public float senstivity;
public float smoothing;
// Use this for initialization
void Start()
{
cam = GameObject.FindGameObjectWithTag("MainCamera");
player = GameObject.FindGameObjectWithTag("Player");
}
// Update is called once per frame
void Update()
{
if (player == null) return;
transform.position = new Vector3(player.transform.position.x, player.transform.position.y + 4, player.transform.position.z);
var mouse = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
var v = new Vector3(-mouse.y, mouse.x, 0) * senstivity * (1 / smoothing);
transform.localRotation *= Quaternion.Euler(v.x, v.y, 0);
}
}
the camera is a child of an gameobject called camera controller which stays on top of the player
(because i want the camera to rotate around a point on top of the player)