my problem is player vertical camera jitter lag when falling. I fixed it by turning interpolate to none on my rigidbody but then it made my game feel horrible and the bullets are super laggy now. Is there anything else I can do to fix the jitter lag when falling without turning off interpolate ? I can send my player movement or camera script if anyone needs it.
Camera stuff is pretty tricky… I hear all the Kool Kids are using Cinemachine from the Unity Package Manager.
There’s even a dedicated Camera / Cinemachine area: see left panel.
If you insist on making your own camera controller, do not fiddle with camera rotation.
The simplest way to do it is to think in terms of two Vector3 points in space:
- where the camera is LOCATED
- what the camera is LOOKING at
private Vector3 WhereMyCameraIsLocated;
private Vector3 WhatMyCameraIsLookingAt;
void LateUpdate()
{
cam.transform.position = WhereMyCameraIsLocated;
cam.transform.LookAt( WhatMyCameraIsLookingAt);
}
Then you just need to update the above two points based on your GameObjects, no need to fiddle with rotations. As long as you move those positions smoothly, the camera will be nice and smooth as well, both positionally and rotationally.
What if my game is first person.
Here is my camera script. first, I’m setting the direction in which the player is start facing, then I check if game is playing, if so then I can control the player looking around. Next is setting the sensitivity and camera rotation logic along with if im on a wallrun which is probably where my issue is somewhere
On the y axis, if I move too fast sliding to rocket jumping. Its like the camera starts kicking back trying to get itself back in place
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerLook : MonoBehaviour
{
[Header("References")]
[SerializeField] WallRun wallRun;
[SerializeField] private float sensX = 100f;
[SerializeField] private float sensY = 100f;
[SerializeField] public float YPlayerStartDirectionY = 180f;
[SerializeField] public float XPlayerStartDirectionX = 180f;
[SerializeField] Transform cam = null;
[SerializeField] public Transform orientation = null;
float mouseX;
float mouseY;
float multiplier = 0.01f;
public float xRotation;
public float yRotation;
private void Start() {
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
yRotation = YPlayerStartDirectionY;
xRotation = XPlayerStartDirectionX;
}
private void Update() {
if (GameHandler.Instance.isGamePlaying()) {
mouseX = Input.GetAxisRaw("Mouse X");
mouseY = Input.GetAxisRaw("Mouse Y");
}
yRotation += mouseX * sensX * multiplier;
xRotation -= mouseY * sensY * multiplier;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
cam.transform.rotation = Quaternion.Euler(xRotation, yRotation, wallRun.tilt);
orientation.transform.rotation = Quaternion.Euler(0, yRotation, 0);
}
}
Plenty of resources out there for setting up Cinemachine as an FPS controller, including specifics of where to put the CinemachineBrain, etc.
If you insist on rolling your own camera stuff in 2024, then it sounds like you wrote a bug… and that means… time to start debugging!
By debugging you can find out exactly what your program is doing so you can fix it.
Use the above techniques to get the information you need in order to reason about what the problem is.
You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.
Once you understand what the problem is, you may begin to reason about a solution to the problem.
Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.