- Home /
The question is answered, right answer was accepted
What is good practice to set Pixels to Units to and how does it actually work ?
Hello Unity Community!
I have a few questions about Pixels to Units. I know that, for the default value (100), Unity considers 100 pixels to be 1 unit.
Let's say my sprites are all 128x128. Should I set Pixels to Units to 128 ? Are there optimal values that should be set for different types of projects ? As in, would you set a different value for a 2D side scroller than for a 3D action game ?
Since this is a subjective question I would suggest you to post it on Forum. :-)
The thing that most affects this decision (i'd say) is whether you need physics or not.
IF i don't need physics i might set the pixel/unit ratio to 1 and the orthographic size to half of the device's vertical resoluution. This way i get to work directly with pixels when i'm positioning my objects.
If i need 2D physics, i have to make the objects in the game roughly in the scale of 1 unity unit == 1 meter (based on the assumption that unity's box2D has the same limitations as its Flash counterpart. Don't know if its true) and then adjust orthographic size and pixel ratio based on how i want it to look.
If you dont need 2D physics you can go with the first solution too. As explained here, 3D physics can be scaled to match your world scale. $$anonymous$$aybe it works for 2D too...
If you're new like me you might want to check out Unity 2D essentials on Lynda.com. You only really pay $20 bucks for the month, watch what you want, remove you subscription... The thing I'm learning is there's so much to getting this thing right. You have to take into account the tile size, unity's unit measures, then there's scripts you can attach to the camera to set it's size dynamically... The reason I mention the video by Freeman is that it mentions this... something to Google to help out is 'Unity pixel perfect camera' you should find some useful information there too... :) sorry to be drab here, I'm just at my whits end with the same problems, lol.
Answer by Loius · Jun 27, 2014 at 08:37 PM
One meter is one unit (by default). So however many pixels per meter your images are is what determines your pixel-to-unit ratio. If you have 100 pixels per meter then you should use 100 pixels per unit.
This is only if you're using Unity's physics. You can change your physics settings and pixel ratio appropriately and get the same results (for example if you're dealing with planetary scales you may want one unit to equal 100 meters instead).
If you're using your own physics then you can use whatever ratio you want, it has no bearing on anything. The only guideline in that case is to keep it reasonable enough that your world will fit inside smallish world units (don't go a million units out from origin).
Thank you everyone for your answers. This helped clear up a few things. $$anonymous$$aybe I'll follow up with a forum post.
I know this is pretty old but... Does that mean that for a sprite 2048x2048px for a real size of 72x72cm I have to set my pixel per unit at... (100cm x 2048px)/72cm = 2800 ?!
yup! That makes sense if you think about it - you want 2048 to be less than a metee, so you end up (from your maths) saying 2800 is a meter, so 2048 gives 72cm.
yes I know, I did the maths before co$$anonymous$$g up with that result but I ain't never seen anybody talking about such a big pixel per unit ^^ I don't know if the physics engine is gonna be pleased with that !
Follow this Question
Related Questions
Unity 2d Sprite size 1 Answer
How to swap sprites? 1 Answer
Circular 9 slice? Draw a circle with constant thickness 1 Answer