jittering when moving

Hiall!

I'm new in scripting and i'm approacing step by step, tutorial by tutorial and headache by headache :)...ok let me explain my problem.

I'm doing a simple test, with a character moving on a plane, and the camera that follow the character only on sliding (mmm...like zelda!), then I added a little smooth to the camera with the mathf.lerp, here is my code:

//smoothfollow camera script
    var target : Transform;
var distance = 3.0;
var slide = 2.0;
var heightDamping = 10;
var rotationDamping = 3.0;

function Update () {
// Early out if we don't have a target
    if (!target)
        return;

    // Calculate the current rotation angles
    //wantedRotationAngle = target.eulerAngles.y;
    wantedSlidex = target.position.x;
    wantedSlidez = target.position.z - 5;

    //currentRotationAngle = transform.eulerAngles.y;
    currentSlidex = transform.position.x;
    currentSlidez = transform.position.z;

    // Damp the rotation around the y-axis
    //currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);

    // Damp the height
    currentSlidex = Mathf.Lerp (currentSlidex, wantedSlidex, heightDamping * Time.deltaTime);
    currentSlidez = Mathf.Lerp (currentSlidez, wantedSlidez, heightDamping * Time.deltaTime);

    // Convert the angle into a rotation
    //currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);

    // Set the position of the camera on the x-z plane to:
    // distance meters behind the target
    transform.position.z = currentSlidez;
    transform.position.y = target.position.y +2;
    //transform.position -= target.position * distance;

    // Set the height of the camera
    transform.position.x = currentSlidex;

    // Always look at the target
    transform.LookAt (target);
}

and here my moving script:

var speed = 10;
var gravity = 20.0;

private var moveDirection = Vector3.zero;

function FixedUpdate() {
    var controller : CharacterController = GetComponent(CharacterController);
    if (controller.isGrounded) {

        moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
        Input.GetAxis("Vertical"));

        if (moveDirection != Vector3.zero) {
            var rotation = transform.rotation; 
            rotation.SetLookRotation(moveDirection); 
            transform.rotation = rotation;
        }

        moveDirection *= speed;

    }

    if (Input.GetButton ("Jump")) {
            moveDirection.y = 3;
    }

    // Apply gravity
    moveDirection.y -= gravity * Time.deltaTime;

    // Move the controller
    controller.Move(moveDirection * Time.deltaTime);
}

@script RequireComponent(CharacterController)

The problem is that the character is perfect in movement but the background shakes a bit with a terrible jitter...you can see th problem directly downloading the .exe project.

Any suggestion or semplification to my code will be accepted :D...

Project exe download: http://rapidshare.com/files/435362527/lolworlds.exe

Thank's a lot!

Hmm I remember a thingy about that, no idea if it helps but definatly worth a try I think. It's a mode on the rigidbody settings that just like your title says has "jerkiness"/"jittering" same same.

Here's the quote:

Interpolate Try one of the options only if you are seeing jerkiness in your Rigidbody's movement.

None: No Interpolation is applied.

Interpolate: Transform is smoothed based on the Transform of the previous frame.

Extrapolate Transform is smoothed based on the estimated Transform of the next frame.

Hope it helps :)

I’ve had the exact same issue with Cinemachine. Crazy shaking screen. Thanks for your tips I was able to fix it. If anyone has the same issue specificly with cinemachine, go to your Cinemachine Brain component and change Update Method to fixedUpdate. It should work like a charm !

Change the value of the FPS using the following code

Application.targetFrameRate = 50;