Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Movement wobbling / jittery => Solved

Discussion in 'Scripting' started by creepi, Jul 27, 2018.

  1. creepi

    creepi

    Joined:
    Nov 10, 2015
    Posts:
    34
    Aloha!
    i have a problem with the movement.
    I have try with transform.translate, rb.velocity and with rb.addforce, rb.moveposition
    Try it with Update and FixedUpdate, with *time.deltatime, time.smoothdeltatime and time.fixeddeltatime... all have the same problem.

    Its working when the position number is not to big.
    Try the movement at example vector 0, 0, 50000
    The cube only movement with lag.
    Set i the same cube, with the same movement script to 0, 0, 0 the movement is not more laggy.
    I don´t find a way to fix it. When i set a gameobject, first at 100001 coming a info it is to large.
    Why is then 50.000 to big?
    I don´t talk with a terrain, its a empty scene, only a cube and a movement script.
    It is not working from -100000 to 100000 ?

    In my test, little lag begin at 20000~
    I try vector forward, without x and y change.
    If the number to large for unity??

    ps. i have test it in Unity 5.6.3f1 and 2017.3.1f1.
    Both version have the same problem.
     
  2. FernandoHC

    FernandoHC

    Joined:
    Feb 6, 2018
    Posts:
    333
    I'd check the profiler for possible warnings and spikes, have a look there and let us know what you find.
    Just as a starter, make sure you have a rigidbody component added to your cube, as it is required for physics performance.
     
    creepi likes this.
  3. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Give this a try: create a new 3D cube in your scene. Attach this script to it and run it :-
    Code (CSharp):
    1. IEnumerator Start()
    2. {
    3.     for (int z = 0; z <= 200000; z += 500)
    4.     {
    5.         transform.position = new Vector3(0f, 0f, z);
    6.  
    7.         if( !Mathf.Approximately( z, transform.position.z ))
    8.             Debug.Log("**ERROR** => Z: " + z + ", Pos Z: " + transform.position.z);
    9.  
    10.         yield return null;
    11.     }
    12. }
    At 100,000 the Inspector will show a warning to bring the object closer to the origin. However, I saw no problem and the debug log did not appear.

    What happens for you doing this? You should see it work. If so, then start adding things from the faulty GameObject into this new Cube until is breaks. Then the last thing added is a candidate for being the source of the problem. :)
     
    creepi likes this.
  4. creepi

    creepi

    Joined:
    Nov 10, 2015
    Posts:
    34
    @FernandoHC
    not 100% sure about the profiler but think all looks fine.
    At the start and later when the cube move position with lag is looks nothing differend. cpu, gpu, all is low used.
    Rigidbody is on the gameobject. Gravity is disable and Kinematic is disable.

    @Doug_B
    thanks for this script, i have try it and have the same as you. Inspector sgow the warning and i get not a debug log info.


    I have now fast create a little scene and upload it on youtube. Maybe its help for understand my problem. I know my english is not the best ;)

    What we see: If the position under 20.000, the movement looks fine, no lag, its constant movement.
    Whenever the position is bigger, the gameobject is moving with lag.
    short clip: > removed <
     
    Last edited: Jul 27, 2018
  5. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Just to double check here, when you say moving with lag, are you meaning that the movement appears jittery?

    "Lag" would indicate some sort of slow down, for example a drop in frame rate. The video shows that the cube is wobbling (or is jittery).

    If it is the jittery aspect that you are questioning, then I would guess that it is as a result of minor differences when calculating cube / camera positions at those high floating-point values. This is basically in line with the warning message that Unity is displaying - it is saying that issues like this will arise at these large numeric value locations. Try keeping the object position values under this 10k boundary.
     
    creepi likes this.
  6. creepi

    creepi

    Joined:
    Nov 10, 2015
    Posts:
    34
    aahhh! yeah, i mean wobbling / jittery : )
    (i read this words firs time : D)

    Wait. You mean the limit is 10.000?
    I think from the insepctor it is 100.000? :eek:

    Okay, then its a big differend about 10k and 100k limit.
    Under 10k is all fine. But its a bit small or i must all object scale down.... hmpf.
    And i think, maybe its a bug or wrong movement script or else...

    Thank you :)


    Now i only can´t understand why Unity3D set limit at 100.000 but the movement is not more correct possible over 10.000. Its a bit confuse. :/


    my problem start at 2min+ (cockpit flickering)


    Again, thank you for the info, then i must try not go over +10k and -10k :)
     
    Last edited: Jul 27, 2018
  7. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Humble apologies - that is a typo on my part. You are quite correct. I did indeed mean 100k. :(

    Yes, I believe it is generally accepted that objects in view of the camera should remain within a certain proximity of the origin. One way, for space exploration style games, is to keep your object at the origin and to move other objects around instead.

    However, I do note that the co-ordinates displayed in your video are not near the 100k limit. But maybe at those values it is just enough to start to become noticeable? Have to say, I'm not sure but best go with the evidence. If it does not occur at smaller position values, then that would imply it is best to stick within them (unless anyone else knows better, of course).
     
    creepi likes this.
  8. creepi

    creepi

    Joined:
    Nov 10, 2015
    Posts:
    34
    Don´t worry =)
    Perhaps anyone have stole the last 0 ^.^
    But 10k or 100k, its change not the problem.
    More then 10k is not possible, don´t know how other guys work, or they don´t need a large map/level.

    „is to keep your object at the origin and to move other objects around instead“
    This is a bit crazy xDDD
    Don´t know how, when do it with a multiplayer... the think, the player don´t move only the object... is really crazy :D
    On this idea i´m not coming :p

    My idea, scale all object down, is a bad think.
    Then i must scale the weapon effects........ all new. No way....
    I don´t think what i do now. I have think i´m the problem here but when no other have a idea, i must think, Unity3D is the problem. :(
    Have try differend movements and all have the same problem when the position go over 15, 20k~

    hm... and -10k to 10k is too small for what i would like do.
    bad situation :/
     
  9. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    I suppose the simplest way to do this would be to have a top level GameObject (called, for example, "Universe Objects") and make everything (not the player) a child of that object. Then you only need to move the Universe Object (UO). You will occasionally need to move the UO back to zero to prevent it getting too large and that will mean moving all the child objects at that time, of course.

    Also, take a look at this link where the same issue is discussed. That links to others that mention other ideas as well, such as scrolling textures etc. There is also this Unity tutorial that may prove helpful.

    I hope you find a satisfactory solution. :)
     
    creepi likes this.
  10. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,419
    This issue has been discussed quite a bit already, here is one thread I remember. It's most likely a floating point precision issue you see. Search for "world origin shifting" to find workarounds (which comes with different issues).

    Just making everything 100 times smaller, isn't going to fix the issue (1).
     
    creepi likes this.
  11. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,558
    Depends on your project requirement, there is indeed number of solutions.
    It has been discussed extensively.

    If you don't have many physics objects, with collides (thousands over), which need be active all the time, shifting origin should be fine.
    What you are looking at, is Floating Origin. There is multiple solutions to that.
    See Kerbal Space Program, how they deal with it. And what challenges they facing.
    Apparent there is noticeable lag spike, when origin is shifted. That is probably due to shift static collides and other objects all together. But I haven't investigated further details. Then you can use double, instead float, to store absolute position.

    Since I am making also space based game, my gameplay scene is within a solar system. I don't need travel beyond it. However, is still big space.
    I have two main parallel cameras. One which is rendering scaled down solar system. Other is rendering current planetary system. I don't need Floating Origin, as all my full scale planets are in 0 origin all the time. But mind, my planets are typically not bigger, than 1000m diameter. And beyond 10k, entering inter-planetary travel.
     
    creepi likes this.
  12. creepi

    creepi

    Joined:
    Nov 10, 2015
    Posts:
    34
    thank you guys for the input!!
    Its help me very much. The problem is no not more a problem :D
    The solution: http://wiki.unity3d.com/index.php/Floating_Origin

    Now i must only change a little bit for my situation... but this not a problem. Its working fine and i understand what its doing. Alone i think i´m not coming on this site/script/idea.
    "Floating Origin" is the magic word what i have missing, thanks so much!!!
     
    Doug_B likes this.