Search Unity

How to do seamless 2D walls like in C&C and Age of Empires 2?

Discussion in 'Scripting' started by Lethn, Jul 2, 2020.

  1. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    https://external-content.duckduckgo.../revision/latest?cb=20130201133102&f=1&nofb=1

    The screenshot above is an example of what I'm talking about I already have a basic 2D placement system setup easy enough but one thing I'm researching currently is how to make the walls seemless. For example when you place one wall piece next to another it turns into a solid wall and increases along the direction you placed it.



    As you can see in this video the sandbags blend in one direction depending on where you place them, is this just really well thought out art? Or is there extra code here doing a check based on what direction the sandbags are being placed?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
    It's kinda both!! Basically they have art for all the possible corners they need and code that resolves it.

    Unity actually has a mechanism for this too, but I confess I haven't used it yet, but I've written plenty of my own games that do this.

    Check it:

     
  3. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    OH! Thanks to this, the tilemap video and your post that makes sense now I think, so what I could do is in fact have empty square colliders next to each wall in four directions if I place a wall inside the trigger it will then automatically instantiate the correct sprite based on which four directional collider it's placed in. That should work I reckon, the only tricky part will be doing a check for both colliders if there's a corner.

    Reminds me a lot of the way more complicated videos I saw on doing building mechanics where objects would snap to each other.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
    You could use colliders, but it might be better to keep track of a grid of your own telling you what is where, and use the coordinate of the click to look it up there. I'd do that personally, but up to you.

    Here's another GREAT video on the tile system:



    Brackeys' stuff is always top-notch and this is no exception. The guy does great work.
     
  5. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    Thanks for the extra information, well I'm thinking about sprites and colliders because I need to be able to do this in runtime and also do a check to make sure that the sprites aren't colliding with trees or rocks and so on can you do this with tilemaps?

    Nevermind answered my own question looking at the learn section :D
     
    Last edited: Jul 2, 2020
  6. NicBischoff

    NicBischoff

    Joined:
    Mar 19, 2014
    Posts:
    204
    It’s called autotile or magic tiles. Look up
    Bitwise autotile and you will find some examples of how this works
     
  7. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    Aha! Okay, I just thought I'd post a note here, I was getting very frustrated with tilemaps because I couldn't get them seemless and was running into all sorts of problems. Turns out it's all because my scaling was inconsistent and I didn't understand the maths behind the tiles properly. Brackey's saved the day when I looked through his tutorial again and looked at how he imported the files, had no idea my scaling was so badly off. This should help me make those seemless walls I want too.

    As a test I did some basic pixelated grass and it's repeating perfectly now :D seems a big part of getting the blending right is just making sure the maths is right for the PNGs you're importing.