#Camera to body rotation jitter
1 messages · Page 1 of 1 (latest)
To resolve your current issues however would probably require "starting" an animation and only cancel + restart it when the goal rotation step changes. If you re execute this each frame then its not suprising it doesnt work properly
im currently js playing around with methods but my goal is to rotate the player to the cameras direction only after the camera has turned far away enough from the bodys forward
Without animation that should be easy by checking the current rotation difference and altering rotation by a multiple of the step width
private void HandleIdleBodyRot()
{
BodyYaw = RB.rotation.eulerAngles.y;
CamYaw = CamHolder.eulerAngles.y;
YawDrift = Mathf.DeltaAngle(BodyYaw, CamYaw); // Angle difference between body and cam
float ABSDrift = Mathf.Abs(YawDrift); // Absolute angle difference between body and camera
if (!IsBodyTurning && ABSDrift > TurnThreshold) // Ensure ur not already turning and that the cam has turned enough
{
IsBodyTurning = true;
// lock the target — DO NOT chase camera
TargetBodyYaw = CamYaw;
Debug.DrawRay(Player.position, CamHolder.forward, Color.red, 10, false);
}
if (IsBodyTurning)
{
TurnSpeed = Mathf.Lerp( MinTurnSpeed, MaxTurnSpeed, ABSDrift / PanicAngle);
float newYaw = Mathf.MoveTowardsAngle( BodyYaw, TargetBodyYaw, TurnSpeed * Time.deltaTime);
Debug.DrawRay(Player.position, Quaternion.Euler(0f, newYaw, 0f) * Vector3.forward, Color.blue, 10, false);
RB.MoveRotation(Quaternion.Euler(0f, newYaw, 0f));
// stop condition
if (Mathf.Abs(Mathf.DeltaAngle(newYaw, TargetBodyYaw)) < StopThreshold) IsBodyTurning = false;
}
}
thats the current thing im doing and now its js a matter of the update rates i do the HandleIdleBodyRot in fixed update and set position and rotation of the camera in late update
my character’s body jitters while turning with the camera, especially during fast turns or rotations beyond the 55° turn threshold. The jitter gets worse the larger the turn is. Lowering the Fixed Timestep from 0.02 to 0.01 or below almost completely removes the issue, but that’s not viable due to performance, so I need to understand why this happens and how to fix it without changing the Fixed Timestep.
i got these values too incase it helps u understand what im tryna do better 😭 🙏🏼
Oh ye i also saw that the isbodyturning is flashing to true and false while i turn at a consistent rate
Ok so i js found the cause the speed is inconsistent
Basically if i turn once 55 degrees then when it stops it snaps so as im turning it keeps snapping