Basically the problem is that my camera controller just seems sort of janky. I’m not sure how else to describe it. How do I smooth it out more, or just make a better one?
I’m a noob at this
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraScript : MonoBehaviour
{
public Transform CenterPoint;
public Transform mimicPoint;
public Transform playerBody;
public float mouseSensitivity = 150f;
float xRotation = 0f;
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
void FixedUpdate()
{
transform.LookAt(CenterPoint);
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
CenterPoint.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
mimicPoint.position = new Vector3(CenterPoint.position.x, CenterPoint.position.y, CenterPoint.position.z);
mimicPoint.eulerAngles = new Vector3(CenterPoint.eulerAngles.x, CenterPoint.eulerAngles.y, CenterPoint.eulerAngles.z);
playerBody.Rotate(Vector3.up * mouseX);
transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y + Input.GetAxis("Mouse ScrollWheel")*transform.localPosition.y, transform.localPosition.z);
//note: transform references the camera object itself
}
}
Hierarchy:
Problem (Video):