Why use world units?

Anything libgdx related goes here!

Why use world units?

Postby Redkin » Wed Aug 14, 2019 2:24 pm

I mean i dont use box2d what is the point of use 16 PPU and divide all textures tiles etc by that number? Maybe is a noob question :P
Redkin
 
Posts: 109
Joined: Sat Apr 22, 2017 7:21 pm

Re: Why use world units?

Postby tenfour04 » Wed Aug 14, 2019 4:32 pm

As opposed to doing what?
tenfour04
 
Posts: 1233
Joined: Sat Jun 18, 2011 3:24 pm

Re: Why use world units?

Postby shatterblast » Wed Aug 14, 2019 5:54 pm

I don't use Box2D yet, but 16 obviously is an exponent of 2. When taking resolutions and physics into account together, that can be a very valuable start to keeping math relatively simple.
shatterblast
 
Posts: 430
Joined: Sun Jul 06, 2014 1:14 pm

Re: Why use world units?

Postby Redkin » Wed Aug 14, 2019 7:45 pm

Thanks for the quick response! Ill add then to my game
Redkin
 
Posts: 109
Joined: Sat Apr 22, 2017 7:21 pm

Re: Why use world units?

Postby ChrisCoder » Fri Aug 16, 2019 12:19 am

I don't know if this is related to Box2D, but I once had trouble understanding the usage of World Units of libgdx as well and tomski explained it in a very simple way that made my lightbulb turn on.

Imagine you're making an SNES style RPG, where you want the character to be able to move in a world that is 100x100 blocks. Now, if you say "My character is a 32x32 pixel sprite, therefore my world needs to be 3200x3200 pixels." That would work. And you could do all of your coding to deal with pixels. So moving the character to the right 1 block would be a movement of 32 pixels horizontally to the right.

However, let's say 10 years later, your game is a hit, and you want to release a High Resolution version with new art. Uh oh. Your character isn't 32x32 now. He's 64x64. All of your pixel specific code now needs to be changed.

If you had used World Units, you wouldn't need to anything. Because you wouldn't have said my world is 3200x3200 pixels. You would have said it's 100x100. And my character is 1 world unit x 1 world unit. The pixels doesn't matter. So when my character moves to the right 1 block to the right in my 100x100 block world I created, I just say move 1 world unit to the right. If you wanted/needed to split it up you could say "Move .5 world units to the right" and you'd move half a block, or whatever fraction of a block you'd need.

I have no clue if this helps, but I hope so. If someone else thinks my explanation sucks... hopefully they can do it better.
ChrisCoder
 
Posts: 2
Joined: Tue Aug 13, 2019 12:44 am

Re: Why use world units?

Postby tomski » Fri Aug 16, 2019 7:20 am

ChrisCoder wrote:I don't know if this is related to Box2D, but I once had trouble understanding the usage of World Units of libgdx as well and tomski explained it in a very simple way that made my lightbulb turn on.

Imagine you're making an SNES style RPG, where you want the character to be able to move in a world that is 100x100 blocks. Now, if you say "My character is a 32x32 pixel sprite, therefore my world needs to be 3200x3200 pixels." That would work. And you could do all of your coding to deal with pixels. So moving the character to the right 1 block would be a movement of 32 pixels horizontally to the right.

However, let's say 10 years later, your game is a hit, and you want to release a High Resolution version with new art. Uh oh. Your character isn't 32x32 now. He's 64x64. All of your pixel specific code now needs to be changed.

If you had used World Units, you wouldn't need to anything. Because you wouldn't have said my world is 3200x3200 pixels. You would have said it's 100x100. And my character is 1 world unit x 1 world unit. The pixels doesn't matter. So when my character moves to the right 1 block to the right in my 100x100 block world I created, I just say move 1 world unit to the right. If you wanted/needed to split it up you could say "Move .5 world units to the right" and you'd move half a block, or whatever fraction of a block you'd need.

I have no clue if this helps, but I hope so. If someone else thinks my explanation sucks... hopefully they can do it better.


Nice explaination of an issue with thinking in "pixels".

If you think about 3D, (which 2d is just a special case of), what size would you be making your models? No such thing as pixels there. Its exactly the same here.
Your game exists without rendering. All the physics/logic/mechanics can work without you renderering anything. So why tie your units down to some imaginary unit that doesn't help you at all? Instead, use something sensible to your game, and detach yourself from being dependent on assets which will break your game if you change them.
tomski
 
Posts: 909
Joined: Wed Jun 26, 2013 6:06 pm


Return to Libgdx

Who is online

Users browsing this forum: Google [Bot], MSN [Bot] and 1 guest