Search Unity

Camera stuttering sometimes when attached to moving object

Discussion in 'Physics' started by CortiWins, Jun 1, 2019.

  1. CortiWins

    CortiWins

    Joined:
    Sep 24, 2018
    Posts:
    38
    Hello friends of unity!

    I'm building a moving platform.It's a cube.
    It has a box collider to stand on.
    It has a box collider with IsTrigger set to true.
    When the player triggers the collider, he is attached to the moving platform by making the platform his parent. ( Like i saw people do in Tutorials )
    Moving with the platform with the player works fine.

    However, when the platform moves up, the camera sometimes stutters a little as if the player is colliding with the platform and i dont know why, because he should be moving with the platform as it's child object, right?
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,505
    If your character has a rigidbody then the parenthood relationship has no effect. Maybe the platform is causing the physics to de-penetrate the capsule from the platform, causing the stutter.

    If that's the case, then a possible solution may be moving the platform with Rigidbody.MovePosition from FixedUpdate. This way the physics should have the effect you expect.
     
  3. SparrowsNest

    SparrowsNest

    Joined:
    Apr 6, 2017
    Posts:
    1,809
    Another solution is not to snap the camera into place, but lerping/smoothing it there.
     
  4. CortiWins

    CortiWins

    Joined:
    Sep 24, 2018
    Posts:
    38
    I didn't exactly find my problem, but a solution instead.

    Physics.SyncTransforms() eleminated the stutter. I had the option set that should auto-sync all stuff anyway, but that doesn't seem to work, so this is required in my case. I got the idea when i remembered why my teleport-script had failed.
     
    Edy likes this.