Hello Guys, I know there have been a lot of threads about this and i have looked through most of them, but I cant figure out a solution. I posted the probelm as a comment on one other thread but it disappeared.
So the thing is, Im making a mobile fps and I decided to use CM for some cool stuff, but when I rotate it jitters.
as I am making a mobile game I use the touch system to get Input for rotation, I get in Update function, and to get the cameras rotation based on my touch input I used a cinemachine POV extension script that I found online.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
public class CinemachinePOVExtension : CinemachineExtension
{
TouchAim aim;
Vector3 startingRotation;
[SerializeField] float horizontalSpeed = 10f;
[SerializeField] float verticalSpeed = 10f;
[SerializeField] float clampAngle = 80f;
public Quaternion rotation;
protected override void Awake()
{
aim = TouchAim.instance;
base.Awake();
}
protected override void PostPipelineStageCallback(CinemachineVirtualCameraBase vcam, CinemachineCore.Stage stage, ref CameraState state, float delta)
{
if (vcam.Follow)
{
if (stage == CinemachineCore.Stage.Aim)
{
if (startingRotation == null) startingRotation = transform.localRotation.eulerAngles;
Vector2 deltaInput = aim.lookInput;
startingRotation.x += deltaInput.x * horizontalSpeed * Time.deltaTime;
state.RawOrientation = Quaternion.Euler(transform.localRotation.eulerAngles.y, startingRotation.x, 0);
rotation = state.RawOrientation;
}
}
}
}
Im using a character mesh which has an animator and is animated with statemachinebehaviour, and it is childed to my Player Transform which has the rigidbody.
I tried calling everything on Update, On fixedUpdate, I tried setting interpoation, and animatePhysics, none of it works. I move the player with rigidody.velocity and rotate it with transform. There is no jittering when I only move, but only when I rotate.
my target is a transform which is childed to the head transform of my character mesh, to make the jittering more clear I moved it backwards on the gif.
void Rotate()
{
Quaternion rot = pOVExtension.rotation;
rot.x = transform.rotation.x; // I made sure not change them so maybe it fixes the jitter but no hope
rot.z = transform.rotation.z;
float rotateSpeed;
rotateSpeed = 20;
Quaternion lookDir = rot;
Quaternion targetRot = Quaternion.Slerp(transform.rotation, lookDir, rotateSpeed * Time.deltaTime);
if (shotCamera.m_Priority < 10) // I change the cam sometimes I made sure it doesnt rotate on second cam
transform.rotation = targetRot;
}
Im certainly doing something wrong but I dont know what, any help is appreciated, Thanks a lot in advance.
