when i rotate the character it shake i try so many methods i try with vector and with quaternion (i used Cinemachine) can any one help
In the line I highlighted you are setting the starting rotation to the target value. This will constantly change as unity tries to lerp with a moving start point. This is probably the cause of the shaking.
Please paste in the code going forward. It is hard to help with screen shots.
- Forum User Guides : How to apply code formatting within your post
using UnityEngine;
using UnityEngine.InputSystem;
public class CamController : MonoBehaviour
{
private InputManager _input;
private GameObject _mainCamera;
private float _rotationX = 0f;
private float _rotationY = 0f;
private Quaternion _targetRotation;
private Quaternion _endRotation;
private float _recenterTimer = 0f;
[Range(0, 1)]
[SerializeField] private float _mouseSen = 0.05f;
[SerializeField] private bool _invertX;
[SerializeField] private bool _invertY;
[SerializeField] private bool _recenter;
[SerializeField] private float _recenterTime = 2f;
[SerializeField] private float _MinY, _MaxY;
[SerializeField] private Transform _target;
void Start() {
_input = InputManager.Instance;
_mainCamera = Camera.main.gameObject;
}
private void LateUpdate() {
CameraRotation();
}
private void CameraRotation() {
if (_recenter && _input._lookInput == Vector3.zero && _input._moveInput == Vector3.zero) {
_recenterTimer -= Time.deltaTime;
if (_recenterTimer <= 0 ) {
_rotationX = 0f;
_rotationY = 0f;
_targetRotation = Quaternion.Euler(_rotationY, _rotationX, 0);
_target.rotation = Quaternion.Lerp(_target.rotation, _targetRotation, 2 * Time.deltaTime);
}
return;
}
_rotationX = _invertX ? _rotationX + -_input._lookInput.x * _mouseSen :_rotationX + _input._lookInput.x * _mouseSen;
_rotationY = _invertY ? _rotationY + -_input._lookInput.y * _mouseSen :_rotationY + _input._lookInput.y * _mouseSen;
_rotationY = Mathf.Clamp(_rotationY, _MinY, _MaxY);
_targetRotation = Quaternion.Euler(_rotationY, _rotationX, 0);
_target.rotation = _targetRotation;
_recenterTimer = _recenterTime;
}
}
no, you probably think they are the same var but they aren’t, the start point is the current rotation of the body (transform in body that cam follow (Cinemachine)) the end rotation is the mouse move value, the code that you are referring to is a recentering code that will not apply unless the timer ends… so my problem is when I rotate the mouse fast the body of the character hesitate
My English is not that good … so forgive me if I can’t explain the problem that well
The run window is just a preview of what the game will look and feel like. Sometimes it has a bit of lag. If your code is working as intended, then try building the game to know for sure if there is an issue. You added a mouse sensitivity setting, so you can adjust that if needed.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.