Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Problem with shaking Object or Camera!

Discussion in 'Scripting' started by cruising, May 7, 2015.

  1. cruising

    cruising

    Joined:
    Nov 22, 2013
    Posts:
    329
    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 :(
     
  2. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    It is probably your code.
     
  3. cruising

    cruising

    Joined:
    Nov 22, 2013
    Posts:
    329
    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?
     
    Last edited: May 7, 2015
  4. danreid70

    danreid70

    Joined:
    Aug 28, 2010
    Posts:
    225
    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.
     
    MilosPolo likes this.
  5. danreid70

    danreid70

    Joined:
    Aug 28, 2010
    Posts:
    225
    Ps: not "literally" in the same function, but bith using the same update function in their own scripts.
     
  6. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    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.
     
    mvinc006 and dterbeest like this.
  7. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    Chances that it is a Unity bug is near to zero. He should post the relevant code.
     
  8. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    While true, your post wasn't helpful at all. You could have at least posted this:

     
    CharlesQH likes this.
  9. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    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.
     
    blizzy likes this.
  10. cruising

    cruising

    Joined:
    Nov 22, 2013
    Posts:
    329
    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
     
  11. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
  12. cruising

    cruising

    Joined:
    Nov 22, 2013
    Posts:
    329
  13. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    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.
     
  14. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,773
    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.
     
    Last edited: May 7, 2015
    mvinc006, dterbeest and blizzy like this.
  15. cruising

    cruising

    Joined:
    Nov 22, 2013
    Posts:
    329
    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
     
    dterbeest likes this.
  16. MMutawe

    MMutawe

    Joined:
    Oct 18, 2018
    Posts:
    1
    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
     
  17. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Its been three years. He probably figured it out already by now.
     
    helmichcurran and StarManta like this.
  18. SpencerGreller

    SpencerGreller

    Joined:
    Oct 13, 2015
    Posts:
    3
    Others may come across the post looking for similar answers