Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Inconsistent physics when changing localscale

Discussion in 'Physics' started by KhenaB, Jul 6, 2018.

  1. KhenaB

    KhenaB

    Joined:
    Aug 21, 2014
    Posts:
    249
    Hey,

    I noticed an inconsistent jump height when flipping my character's orientation mid air, so i made a test scene.

    They're simple sprites that get launched by setting their velocity once, one of the sphere gets flipped twice, the other 20 times, the more they flip the less height they get, why does changing localscale.x affect physics, and what can be done about it?

    Jumping.gif
     
  2. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,040
    Can you post the project? If not, can we see the class (whole class) where you're doing the flipping?
     
  3. KhenaB

    KhenaB

    Joined:
    Aug 21, 2014
    Posts:
    249
    Sure, here's the project
     

    Attached Files:

  4. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,040
    Interesting find. Seems like any kind of transform modification on RigidBody messes with physics.
    I'm not sure if this is expected behavior or not.

    I solved it by
    -separating jump and flip into two scripts,
    -make an object with just Jump script, Collider and RigidBody
    -and an object that is it's child and only does the sprite flipping.

    But the way I kept track of time (got rid of coroutines at some point while testing their influence) is fugly.
     

    Attached Files:

  5. KhenaB

    KhenaB

    Joined:
    Aug 21, 2014
    Posts:
    249
    I tried removing the flipping part from the script, and make a separate script just for the flip, and add the script to the child which flips the parent, and the same thing happens, unless i misunderstood your explanation?

    Edit: I'm taking a look at your project and i see what you mean, however I'm not sure why my version isn't working as I pretty much did the same thing, I'll keep messing around and maybe submit a bug report
     
    Last edited: Jul 6, 2018
  6. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,040
    This is the point where you made the same mistake again. Don't flip RD, flip it's child, the sprite renderer.
     
  7. KhenaB

    KhenaB

    Joined:
    Aug 21, 2014
    Posts:
    249
    Oh yeah not flipping the Rigidbody would probably solve the issue, I'll see if this is a bug first before thinking about setting things differently as this would be a pain with my big project
     
  8. KhenaB

    KhenaB

    Joined:
    Aug 21, 2014
    Posts:
    249
    I tried it in the new Unity version 2018.1.6f1 and the issue doesn't appear so I guess this was a bug, which version did you try this on?
     
  9. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,040
    2018.1.1f1.
     
  10. KhenaB

    KhenaB

    Joined:
    Aug 21, 2014
    Posts:
    249
    Upgraded my project and the issue is completely gone, thanks for helping out.
     
    FMark92 likes this.
  11. Miguel-Herrero

    Miguel-Herrero

    Joined:
    Jan 19, 2015
    Posts:
    11
    I think I'm having this problem on 2018.2.0f2. I just updated the project from 2018.1 and changing localScale (I'm using a wobble effect upon startup) messes with the rigidbody position
     
  12. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,040
    Idk, maybe it all works as intended and writing to transform just skips a physics frame for that object.
     
  13. KhenaB

    KhenaB

    Joined:
    Aug 21, 2014
    Posts:
    249
    I haven't tested 2018.2 yet, you can test the scene that I attached in the previous post and check if the spheres are synchronized or not, if they are not someone should make a bug report, I'll update soon but right now i'm a bit busy
     
  14. Miguel-Herrero

    Miguel-Herrero

    Joined:
    Jan 19, 2015
    Posts:
    11
    Hmmm.... your test works fine :S

    I'm using 3d physics, but even changing the code to use rigidbody & 3d colliders it works fine.

    I'll have to check my code, but our game is quite big now to do small tests.