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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Implementing 2D physics with pixel perfect sprites.

Discussion in '2D' started by jdovermy, May 12, 2015.

  1. jdovermy

    jdovermy

    Joined:
    Mar 26, 2015
    Posts:
    12
    Hey Everyone,

    So I'm creating a 2D game where the sprites are set to 1 Pixels per Unit. I have it set to this because I've read that this is a good way to get a "pixel perfect" look and I want the sprites to be high quality. The problem that I've run into is that it's making the 2D physics very difficult to work with. I have to set huge values for things like gravity and jump power for example because the sprites are giant in comparison to a Unity unit.

    My question is, should I skip the whole 1 pixel = 1 unit thing and set it back to the default of 100? Will it have any effect on sprite quality? Is it good practice to stick to the default Unity scale when using any kind of 2D physics? I'm fairly new to Unity and game development in general so I apologize if this is a no brainer question :)

    Thanks everyone and thanks to @Adam Buckner for the Twitter reply!
     
  2. keely

    keely

    Joined:
    Sep 9, 2010
    Posts:
    967
    For pixel perfectness having 1 or 100 pixels per unit doesn't really matter. You can achieve it with both by just adjusting your camera size correctly and perhaps snap your objects to every 0.01 unit instead of 1 unit in the scene view.

    For physics it is much better to have 100 than 1 for meaningful simulation. Physics simulation tends to be allergic to very small or very large scale.
     
    theANMATOR2b likes this.
  3. jdovermy

    jdovermy

    Joined:
    Mar 26, 2015
    Posts:
    12
    Hi Keely,

    Thanks for the reply! Ok, I'll stick to 100. One more question relating to the 2D physics if you have the time. I want the jumping in my game to be very responsive, quick jump and quick fall. I've tried increasing the gravity and it gives me the desired effect, but sometimes my character sprite sinks into the ground, goes through the collider, before bouncing up. I'm assuming this is because the gravity is too strong. Any way to get that really quick jump without increasing the gravity so much that it pushes the sprites through the ground?

    Thanks again!
     
  4. Gardes

    Gardes

    Joined:
    Apr 7, 2015
    Posts:
    46
  5. jdovermy

    jdovermy

    Joined:
    Mar 26, 2015
    Posts:
    12
    Hey Gardes,

    Thanks for the reply. I'm using AddForce to give the character "jump power". The problem is, the default gravity feels way too "floaty". I'm not adjusting the gravity during runtime or anything, just setting it higher to get rid of the floatiness. But if it's too high the sprite falls through colliders, if it's set too low I don't get that quick jump and fall feeling. Hope that makes sense.

    Thanks!
     
  6. jdovermy

    jdovermy

    Joined:
    Mar 26, 2015
    Posts:
    12
    Figured it out! I set the characters Rigidbody2D "Collision Detection" setting to "Continuous". No more falling through the colliders.
     
  7. Gardes

    Gardes

    Joined:
    Apr 7, 2015
    Posts:
    46
    Oh, ok cool :) Im glad u solved it :)
     
  8. probhe31

    probhe31

    Joined:
    Sep 21, 2015
    Posts:
    2
  9. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    832
    theres a few plugins on the asset store but the easiest way is to make a fixed update script that you put on your objects that forces the transform.position to your ppu grid.
     
  10. Zaflis

    Zaflis

    Joined:
    May 26, 2014
    Posts:
    438
    If you want some retro-look with pixels ingame you have other option too; rendering into texture. I haven't experimented with that in Unity yet, but if you render into say 320x200 texture and then scale up up to fill screen, every sprite will always be correctly pixelated. Even if you rotate them. You can even use sharp 3D models and they'll end up looking pixelated.