Problem with shaking Object or Camera!

Hello!

Im working on a space game, the space and the distance between planets are great, and the ship is fast!

How ever…when i after a while (lets say 30-60 sec) been flying the ship slow or fast, the ship starts to shake or vibrating.
When i stop the ship it stops to shake after some seconds while the camera aint moving, if i zoom/rotate the camera around the ship it start to shake/vibrate again untill the cam stands still.

If i go full speed ( extreamly fast) it shakes even wors. My guess is that it is the camera thats make it looks like the ship is shaking…because even the visible planets shakes a little when zoom or rotate the cam.

Cant the camera handle the speed or the distance traveled? or is it something else that could causing this? its so disturbing for the eyes :frowning:

It is probably your code.

I have had the same problem with other camera script on a regular player on a terrain, witch make me believe it is the actually unity camera that bugs out…but i could be wrong.

i know you dont know what code i have, but whats comes in your mind when you say it is probably the code?

EDIT:
i made a test, was flying untill the cam got shaky, looked at both the cam and the ship in the scene…nothing was vibrating or shaking there, just in the “Game”
how come?

Check to see where in code the ship position is updated, and where the camera is updated. I’ve: update(), lateupdate(), fixedupdate(). Make sure both ship and camera positions are updated in same update because timing could be different enough to cause that camera jitter.

1 Like

Ps: not “literally” in the same function, but bith using the same update function in their own scripts.

This is not helpful at all.

Anyway, this sounds like you are running into floating point issues where the precision gets lower and lower. If by moving your ship, do you get ever farther away from the origin (0,0,0)? If so, you will run into problems at large distances. To prevent that, you need to shift everything back to near the origin.

2 Likes

Chances that it is a Unity bug is near to zero. He should post the relevant code.

While true, your post wasn’t helpful at all. You could have at least posted this:

1 Like

Is there any chance that some Vector3 values are getting too large and you’re losing precision? It sounds like your environment is really large and possibly the values are too large.

This talks about the issue somewhat (mentions camera jitter): http://www.davenewson.com/dev/unity-notes-on-rendering-the-big-and-the-small

To quote that article: This may not seem like a huge problem, but this issue of losing floating point accuracy at greater distances is the reason you start to see things like camera jitter and inaccurate physics when you stray too far from the origin. Most games try to keep things reasonably close to the origin to avoid these problems.

1 Like

Thanks for all replys!

Yes it is large since i use empty scene as you where just starting a new scene (gues the distance of the objects calculate the size of the actually built game scene?)

Then i have:

1: 1 Object that contains the stars (no skybox)
2: Sun at size “1391” Distance “0,0,0”
3. Earth at size “127” Distance X “44950”
4: Mars at size “67” Distance X “-62790”
5: Jupiter at size “600” Distance Z “-80000”
6: Starship at size “0.1” to not make the distance enormous
7: A Spacestation sized to fit a realistic size to the ship

I have tried with FixedUpdate and LateUpdate, but then the camera ends up far behind the ship and not centered like the values says in the inspector.

Maybe i just could make every object small as atoms? lol but i guess the camera has its limits

The solution is to keep the camera and nearby objects near the origin. Objects far away cannot be seen anyway, or their shaking cannot be seen. Check out this post as well: http://forum.kerbalspaceprogram.com/entries/54-Scaled-Space-Now-with-100-more-Floating-Origin

I didnt understand all of it, but a bit of it…i guess lol. a tutorial for that would be greate for many space creators!

It basically boils down to this: Why do you need to keep Jupiter at z=-80000 if you’re not near it? You can’t see it anyway. And if you go into map mode (assuming you have one), you use a scaled-down version of your solar system instead, where the positions of all the planets are in sane ranges.

Here’s a clip of the KSP developers talking at Unite about dealing with this exact problem. The talk is a little bit clearer and better laid out than the blog post linked above, IMO.

3 Likes

Why? because i didnt know any other way to build a space, and i didnt even know about this problem untill today. You sure see Jupiter on my screen on that distance because it is big and cam clipping is greate.

And i have exactly no idea how to start/make that he did

1 Like

Hi , the problem is when you use two different update method (one for camera and another for player/ship) they during time there will be a gap within the process calling time.

so what you need to do here is to define a priority update method and you can use “LateUpdate” for camera to follow ship. However there will still be a problem (but less than before), so what you can do is to use a method to SMOTH the camera movement by using “Vector3.Lerp(prevCameraPos, nextCameraPos, smothSpeed)” , smothSpeed is a value between 0-1 (0: prevPos → 1: newPos) , for me the value 0.125f did work , I mean you need to keep testing the best value xd

Its been three years. He probably figured it out already by now.

2 Likes

Others may come across the post looking for similar answers

1 Like