rigidbody vibration

Hi

I have this fast moving airplane that I move by script. It’s pretty simple, I calculate where it should be and I tell the rigidbody to place it there.
What’s odd is that the plane vibrates like crazy. Like it moves back and forth, just a bit, but enough to make it look way too shaky.

I tried everything, kynematic off, interpolate, extrapolate, none… nothing

The code is very simple, inside the FixedUpdate:

Vector3 velocity = currentHeading.normalized * (currentVelocity+(acceleration *Time.deltaTime));
rigidbody.MovePosition(rigidbody.position+velocity);

any ideas how to stop it from vibrating? In theory, without gravity and kinematic, it should not move without me telling it to :?

1 Like

I had a particle emitter attached to the basic FPS controller to simulate snow and it was jittery as well. I unchecked use fixed update and the snow no longer jitters. Perhaps these issues are related?

1 Like

nope. it must be some floating precision error.
I removed the rigidbody and did a simple transform.position=

It’s still vibrating.

I guess I can somehow use AddForce and that way let the physics engine handle it and avoide the vibration but I can’t figure out a way to add the previous example as a force. I tried with AddForce as velocity, acceleration,etc… no luck.
Any ideas welcome :slight_smile:

1 Like

Don’t see the reason to put this code in FixedUpdate, since you just change object’s position and nothing more.

1 Like

it doesn’t matter where i place it, it vibrates still, i can put it on Update too

1 Like

The problem may actually be in your camera script. Change it to LateUpdate().

LateUpdate()… nothing, same thing
If it was my camera script I guess the whole screen and objects on them would vibrate. Only this gameobject vibrates.

I know it can be solved by using AddForce or AddRelativeForce, anyone knows how I can implement those simple 2 lines of code into a AddForce to the rigidbody?

Well, you typically don’t want to directly move a rigidbody; rigidbodies like to manage their own movement, and you should let them. Turn kinematic off and set the velocity property of the rigidbody:

rigidbody.velocity = newVelocity;

Also, your “velocity” variable in your code is a “float”. I don’t even know how that compiles, considering that it should be a Vector3.

One more thing: This is C# code, right?

that was a typo, I just fixed it. Velocity is a vector3.
All you said was tried and still vibration continues. These are all the alternatives I’ve tried:

  1. Update, FixedUpdate, LateUpdate
  2. Rigidbody kinematic, on/off. Interpolation none, interpolate and extrapolate.
  3. Moving the rigidbody with MovePosition, directly with .position or using .velocity.
  4. Moving the rigidbody with AddForce
  5. Ignoring the rigidbody just for testing purposes, removing it completely from the object and just using transform.position

ALL of the tries, make the object move as expected. Meaning, the object moves at the speed and direction I intended it. But it shakes, it has a very noticiable vibration. The faster it goes, the more it vibrates.

The other thing then could be my camera the one that it’s shaking, but no other object in the scene shakes so that seems to rule it out.

Joaquin

Can you post your whole script? It seems to me that you’re not giving the whole thing and some critical variables have been left out.
Post your camera script, too; it may be that it’s shaking so little that only the object closest to the camera (i.e. the plane) seems to shake.

Another thing would be to watch it from the Scene view rather than the Game preview to see if it’s really shaking in the world.

Really, that’s just the whole script. The typo was just because I renamed the variables here to make them more clear.
There is nothing weird, odd or extraordinary about it.

About the camera, I’m using the smoothfollow script from the standard assets, again, nothing extraordinary.
Objects that doesn’t move, they don’t vibrate, it doesn’t matter if i get close to them. It’s only the objects that move FAST the ones that vibrate. So go to 50km/h it’s ok, going 100km/h begins vibration. It’s an airplane btw.

It seems some kind of floating number error. I can’t check it since all Vectors are float and there are not double alternatives so unless I implement my own vector3 it would be hard to figure.

I guess there is no solution for this one then.

Ok, I figured something new.

The smoothfollow uses LateUpdate, which makes sense. But, if I change the LateUpdate to FixedUpdate, my moving object looks fine!
Of course, the object that smoothfollow follows, looks shaky now. That makes sense since it changes position between the calls.

But I don’t get why if I set the SmoothFollow script to FixedUpdate, my fast moving object looks fine. They seem to be synchronized that way. But then my other moving object (which is also in FixedUpdate) that the camera follows, it’s shaky.

2 Likes

I’ve fixed it and it’s droven me nuts for days so… for people that might have the same problem in the future, this is the solution and what might have lead you into it.

If you use the standard smoothfollow script and experience shaking of the object that you follow, the documentation states that you can set the rigidbody of the object to interpolate and it will fix it. This is true, it will fix the shaking of that object, but it will make every moving object in your scene shake when moving at high speeds.

Solution: Don’t set it to interpolate. Leave it as ‘none’ and move the smoothfollow code from LateUpdate into FixedUpdate.
Done, no more shaking of your main character and no more shaking of your other objects.

So simple once you know :slight_smile:

8 Likes

Thank you very very very much! The 2D follow script is normal Update, changed to FixedUpdate and no more wiggle!

1 Like

You probably don’t need Time.deltaTime either since fixedupdate runs at a fixed rate, and interpolation is basically doing that for you on the rigid body.

2 Likes

I was having the same problem and none of the fixes posed in this thread worked.
What did work was changing Is Kinematic from unchecked to checked.

Unfortunately, this prevents my tank from getting knocked around when it is hit by an explosion.

I am using the Basic Tank Kit from the Asset Store.
There is no problem when the tank is on terrain, there is only a problem when it is on a plane.

Here is the code

function FixedUpdate () {
tanksVelocity=2;
transform.Translate(Vector3(0, 0, tanksVelocity * Time.deltaTime));

Fix found by Sobhan Bahrami;

add the Smooth Follow script to the camera.
I also had to set the height dampening to a high number 100

man… I’ve tried all of these things… still shaking. I can’t however make my player into “is Kinematic” because then I can’t apply forces to it (which is what my movement and flying scripts use. I have to use this type of movement script so my character (who is a flying squirrel) can climb trees. and now… he can fly, but when I turn the character shakes a lot. (only when I’m flying and turning)

SmoothFollow camera on. Interpolate on player = none. When I changed from LateUpdate to Fixed update, the whole of everything is jilted, very choppy movement.

I had same problems with riggid body attached on gameObject. I solved it in this way.I just break kinematic i one frame and again break afther 1 sec.It is js

var a = 0;
function Update () {
if (a == 0) {
GetComponent.().isKinematic = true;
a = 1;
fd ();
}

}

function fd () {
GetComponent.().isKinematic = false;
yield WaitForSeconds (1);
a = 0;

}

:slight_smile:

Thought I’d throw in my experience here for posterity.

I too had these annoying issues with shaking/vibrating. Depending on the “variables” I changed it either caused the camera to shake or the object its following.

By “variables” I actually mean things like:

Camera Movement script using LateUpdate vs FixedUpdate vs Update (technically, it’s not moving with physics so it should always be in LateUpdate…tried anyhow)

Putting physics in Update (again, technically not what I’m supposed to do)

etc, etc…

All of these kluge type fixes not only didn’t work and just transferred the shaking to another entity, but are bad practice in general.

So, in the end what I did was set my object that the camera is following to “interpolate”. I still got a bit of jitter in the editor but when I build the project the jittering/shaking/vibrating all goes away. That’s it. Simple and you don’t have to mess with how functions are meant to be used (update, fixedupdate, lateupdate).

2 Likes