3
\$\begingroup\$

I am planning to make a 2d tile based platformer with big world like in terraria.

I have some questions to ask on how to manage this big world in Unity3D.

The Scenario

World Size = 1000 x 1000 = 1 Million Tiles

Tiles Viewable in Camera = 32 x 24

Chunk Size = 32 x 24

There will 9 Chunks present in the scene at one time ( Center,Left,Right,Top,Bottom and 4 diagonal), total tiles present at one time 6912

Questions

Every tile is a gameObect with a box collider on it, a script containing the tile information(health,type), wouldn't this take a lot of memory and processing because there are 6912 tiles present in the scene all the time?

If I generate a mesh of chunk, how will the collision be handled(Considering every tile is destructible)? Will I have to redraw the mesh even if a single tile is destroyed? Won't this be less optimized as compared to the tile based approach?

I'd really like to if anyone here has done this in unity and will be really thankful if you share your approach of handling big world. Thanks!

\$\endgroup\$
1
\$\begingroup\$

I try with some consideration. 1000 * 1000 is similar to a bitmap 1024*1024 , something you can easly store in memory.

You can "cablate" the type and health of each block in the color / alpha of each pixel. Then you istantiate / deistantiate (or activate / deactivate) the blocks at runtime refering the camera position. So you can have 32 x 24 blocks (+ a delta for caching) active on the screen gaining in performance.

If you don't like the bitmap approach you can define a bidimensional array of structs..

Finaly, the "destructibles" tiles are only a sub set of the tiles (for example the top ones where some character walks?), again activate / deactivate the "destructible" script at run time. (i.e when you destroy a block , check if you can activate the neighbourg scripts)

\$\endgroup\$
  • \$\begingroup\$ thanks for the reply, have you tried this method in unity? I am probably gonna go withe the tile method, create tile prefabs and reuse them \$\endgroup\$ – ahmedkl Apr 24 '15 at 6:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.