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

Possible Physics2D bug with PixelsToUnits or am I doing something totally wrong?

Discussion in '2D' started by DarkMarmot, Dec 9, 2013.

  1. DarkMarmot

    DarkMarmot

    Joined:
    Nov 13, 2013
    Posts:
    22
    I've been making a 2D game that is Pixel perfect and scaling using the camera at even multiples of resolutions to fit the device screen.

    I recently started testing physics with the new Rigidbody2D component -- just animation, not collisions -- and found that no matter how high I set the velocities, nothing seems to move more than 1 pixel per update.

    I attached my own behaviors simulating gravity and velocity and it works as expected.

    Is this an issue or any ideas if I'm doing something terribly obviously wrong with the Physics2D?

    Thanks!
     
  2. TomasJ

    TomasJ

    Joined:
    Sep 26, 2010
    Posts:
    256
    There is a fixed speed limit 120 units per second (Box2D b2_maxTranslation value of 2 at 60 ticks per second).
    Maybe you are using a very low value for PixelsToUnits and growing the sprites too much?
     
  3. DarkMarmot

    DarkMarmot

    Joined:
    Nov 13, 2013
    Posts:
    22
    Thanks! my ratio is 1:1 because I am creating a retro pixel art game and working in pixels for layout is really helpful. I didn't know about the max translation though....

    That explains it :)
    -s
     
  4. TomasJ

    TomasJ

    Joined:
    Sep 26, 2010
    Posts:
    256
    Just curious - is it really that much better to have a 1:1 ratio versus say 1:100? Where is the workflow for 1:100 broken?
     
  5. unitylover

    unitylover

    Joined:
    Jul 6, 2013
    Posts:
    346
    1:100 has worked beautifully for me for several different games so far. I have noticed that some developers are using grid size as their ratio for ease of use when moving across a grid but other than that I can't see any benefit from swaying from the default 1:100. Hoping Marmot will chime in with some info. :)
     
  6. DarkMarmot

    DarkMarmot

    Joined:
    Nov 13, 2013
    Posts:
    22
    The only real advantage has probably been that all of my scene view placements were in pixel coordinates. As it was my first attempt at Unity2D and working with scripts to manipulate the orthographic camera, it was easier to get set up. I simply didn't know about the Box2D max translation issue. Since I'm not using any serious physics interactions, faking it works fine for now. In the future, I will probably just retain the default. And if I wasn't doing pixel-perfect dynamic layouts with graphics being scaled at integer values to multiple resolutions, it wouldn't have even come up.

    Thanks for the help/comments!

    P.S. -- Tomas J, your comments are scaled to 0 width on my browser (chrome win7). I have to inspect source to read them -- no idea why, it only seems to affect your comments on this site....