- Home /
My character "shakes" when I smooth out the camera movement
Hello, I have a simple character controller and a simple camera controller that is supposed to follow the player in a smooth way (with a lerp). But when I enable smoothing on the camera, the player's movement seems jerky... when I remove the smoothing or when I freeze the camera, the character's movement is nice again !
Here is a video that shows that...
Here's my code :
Character Controller :
private void Update()
{
// (other stuff)
rb.MovePosition(rigidbody.position + (moveInput * speed * Time.deltaTime));
}
Camera Controller
[SerializeField] private Transform player;
[SerializeField] private float smooth, smoothAngle;
[SerializeField] private Vector3 offset;
private Vector3 referenceVelocity = Vector3.zero;
private void Update()
{
Vector3 desiredPosition = player.position + offset;
transform.position = Vector3.SmoothDamp(transform.position, desiredPosition, ref referenceVelocity, smooth * Time.deltaTime);
float smoothedAngle = Mathf.LerpAngle(transform.rotation.eulerAngles.x, angle, smoothAngle * Time.deltaTime);
transform.rotation = Quaternion.Euler(smoothedAngle, transform.rotation.y, transform.rotation.z);
}
Answer by Renardjojo · May 11 at 09:53 AM
Hey !
You can try to use FixedUpdate to move your rigibody. It could probably fix your issue, as you can see in Unity example : https://docs.unity3d.com/ScriptReference/Rigidbody.MovePosition.html
Let me know if it work !
Jonathan
Your answer
Follow this Question
Related Questions
Jerky Camera Problem for Dash Ability [Cinemachine, Unity 2D] 1 Answer
camera script not working 1 Answer
[SOLVED] MobileGame - PlayerMovement is not working properly 1 Answer
I'm a bit new but when my camera rotates with the player model to look around it kind of jitters 0 Answers
How do I stop my player or camera from jittering during player movement? 1 Answer