- Home /
Question by
mambo_2 · Jul 27, 2015 at 10:38 AM ·
cameraphysicscamera-movement
Camera smooth follow jitters
As states in my question's title, I have a custom camera follow script which I use in my 2D platformer, the problem is the camera keeps jittering I tried all sorts of changes but nothing seems to work, I move my character by settings it's velocity directly inside FixedUpdate I linked the code below, any help would be appreciated.
Camera Follow inside LateUpdate :
void ControlCameraPosition()
{
// Vector3 startPos = transform.position;
if(followX)
{
xMove = Mathf.SmoothDamp(transform.position.x, target.position.x + offsetX, ref VelocityRef.x, xDamp);
}
else
{
xMove = transform.position.x;
}
if(followY)
{
yMove = Mathf.SmoothDamp(transform.position.y, target.position.y + offsetY, ref VelocityRef.y, yDamp);
}
else
{
yMove = Mathf.SmoothStep(transform.position.y, (zoomedOutSize - startCamSize) + cameraStartPosition.y, yDamp);
}
if (GameStateManager.currentState == GameStateManager.GameStates.Winning || GameStateManager.currentState == GameStateManager.GameStates.Won)
{
xMove = Mathf.SmoothDamp(transform.position.x, cam.rect.width / 2 + target.position.x, ref VelocityRef.x, 0.5f);
yMove = Mathf.SmoothDamp(transform.position.y, cam.rect.height / 2 + target.position.y, ref VelocityRef.y, 0.5f);
}
transform.position = new Vector3(xMove, yMove, 0);
//Debug.Log(transform.position.x - startPos.x);
}
Character movement inside FixedUpdate :
if (controlVelocity && CharacterRigid.velocity.x != xSpeed)
CharacterRigid.velocity = new Vector2(xSpeed, CharacterRigid.velocity.y);
Thank you.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220611233142im_/https://answers.unity.com/themes/thub/images/avi.jpg)