A grid based block game?, Terraria / Minecraft how would it be done?

Hi I’m just interested in how this would be created in unity3d with the new 2D functions, how would you create it? I guess it would be like a 1x1 sprites with collider 2d on? would it detect if two was touching, also is it possible to detect if it is the top/bottom/right or left of the collider that is touching another?

the image bellow might explain it better?

thanks
Fire

You wouldn’t detect it with the actual sprites. The sprites would simply be a representation of the data you have stored and are manipulating. It’d probably be in a standard array, since they’re blocks and can’t overlap or anything.

not sure how well unity would handle potentially millions of sprites, might need to add some sort of quadtree/sprite rendering system which could be a pain.

Well, as long as you could figure out a way to only draw a selection of a 2d array of sprites that are visible to the player at a given time, then things wouldn’t be out of control… would take some thinking to write the control for that part but once you had that done, you could worry about creating dynamic collisions (if blocks get removed or added you must change collisions) which is where I feel like things would get difficult.

It could be done though, for sure - just a matter of optimization and getting past the major roadblocks. Personally I think this would be a nice tutorial/example project to go along with the 3d minecraft clone project thats floating around the forums… infact some of the stuff used in that could be applied in a 2d nature to this even… maybe… lol

EDIT I was thinking, if you applied this java projects methods in unity, you could get a big headstart:

http://www.youtube.com/watch?v=jM7-5ScztpQ

“How to make a Java “Minecraft 2D Platformer” game”

or also there is this java project meant to be a clone of terraria:

http://www.terrariaonline.com/threads/open-terraria-rewrite.94475/

“Open Terraria Rewrite”

and another of those terraria clones I beleive in XNA this one though:

http://www.terrariaonline.com/threads/open-texture-pack-needed-for-open-source-terraria-clone.94287/

“open source terraria clone”

depends on your resolution/block size I guess… running a 4x4 block with a 1920*1080 is still over half a million blocks… if you are attaching physics/lighting to each one or something you definitely will run into issues.

it can be done, but you are looking at a whole bunch of research before you make it haha

Yes thats true, it all comes down to the scope of things, if its terraria’s detail level (block size) then things are do-able, but much beyond that and you need to really get to optimization, or its only gonna run on cutting edge stuff decent, which is only ok if your not planning on releasing for another ten years :stuck_out_tongue:

Here’s an online demo that generates levels with a million tiles made out of sprites. I used a pooling system so that you can have levels much bigger than the screen without any additional objects. The “colliders” in this case are really just bits in an array…if the bit is on, that tile is considered to have a collider, which is checked with a GetCollider function. Likewise, checking which blocks are touching would be done with the GetTile function, which behind the scenes is really just a matter of numbers in an array. For something like this, using arrays is a lot more efficient than physics.

–Eric

Very cool. I have been watching for a release on your tile system - is it available now?

EDIT oh wait your SIG says it is :stuck_out_tongue:

Yep, also on the Unity Asset Store.

–Eric

Hey, I also got a Terraria-like world generation engine on the Asset Store, the Pixel World Engine.
It just got released, and I’m working hard on it to make it a great world generation tool, a viabile option for many types of games! Also, it is on a sale now!
Here’s a link: u3d.as/80q