- Home /
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!
If you want it to look smooth and updated every frame, do use Update ins$$anonymous$$d of FixedUpdate
I had the player and camera set to FixedUpdate and was still seeing jitter on the player. I noticed this only occurred when forces were applied to the player via my input control script.
To fix this, I set the rigidbody on the player to "Interpolate: None" and the problem completely went away.
THAN$$anonymous$$ YOU!!!!! I have been having the jitters for days now....finally this rehab worked :)
Answer by Proclyon · Dec 07, 2010 at 12:10 AM
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 :)
Hi Proclyon thanks for the interest :)...unfortunately it seems that the case you explain doesn't solve my problem, cause i'm not using a rigidbody on my character and there's any interpolate option in the charactercontroller.
Thanks again!
Hmm sorry to hear that, and you are most welcome :) I don't know if I can see the problem elsewhere. But what I usually do is try to cut down the scope of the problem by commenting bits and pieces or look back at the design ( which if well made cuts down debugging and problem times to an infinitesimal value )
SOLVED :D...after talkin with a programmer he told me that maybe the problem was in the sync...and he was right! I changed the update of the script camera from "update" to "fixedupdate" and now it seems to work correctly! Thank's anyway for the support and suggestions! Stay tuned on my progress eheh :)
wow that's superweird. FixedUpdate is specifically designed for being used for rigidbody and physics stuff. Well whatever works huh :D
I just had the same problem and found this. Yes -- the Player on FixedUpdate
and Camera on Update
was the problem. Changing the camera to also FixedUpdate
got rid of the jitter.
Answer by Mohamed Adly · Oct 29, 2014 at 03:19 PM
Change the value of the FPS using the following code
Application.targetFrameRate = 50;
Answer by lulubiceps · Mar 08, 2021 at 10:05 PM
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 !
Your answer
Follow this Question
Related Questions
Character Controlling grinding along any non-flat Terrain 1 Answer
Charactercontroller jittering while jumping into wall 0 Answers
Character move in camera direction 1 Answer
Character Controller Jitter On Platform With Animation 0 Answers
Character Controller Capsule collider making camera Jitter 1 Answer