Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Building 2D Levels

Discussion in '2D' started by Panchos, Jun 27, 2015.

  1. Panchos

    Panchos

    Joined:
    Oct 31, 2012
    Posts:
    34
    Hey guys,

    First off, I just started using Unity yesterday so I'm about as new as they come, so apologies in advance for the noobness of my questions.

    I have a little 2D project started up where I can move my player around (top down view), camera follows etc, but next I need to move onto level building. My game will essentially be one level, maybe around 3000 x 3000 made up of 16x16 tiles.

    My question is, what's the best way of making the level? I've made rigidbody objects that I can assign as obstacles already (just to test), but is it possible to assign an entire layer as an obstacle instead? That way I can have all the level walls on that layer and just do a blanket 'if player collides with object on this layer' condition. Or do I have to make every single wall sprite rigidbody and do it that way?

    Any pointers or links to info you can share?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Rigidbodies are only for objects that move; if objects don't move then they don't need rigidbodies. Sounds like you should use a tile system. Using an object for every tile is a bad idea.

    --Eric
     
  3. MoonJellyGames

    MoonJellyGames

    Joined:
    Oct 2, 2014
    Posts:
    324
    Uh oh. The project I recently started is tile-based, and so I need to figure out how to handle collision with raycasts or something. I can't imagine how I would build my game without making each tile an object because they need to be destructible. Hmm.
     
  4. TheCodez

    TheCodez

    Joined:
    Sep 19, 2014
    Posts:
    14
    There are tile systems on the Asset store. I bought one for like 20 dollars (I don't remember the exact price) called SpriteTile. It should do what you want.
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The general concept is that you use a data structure to represent a tile, and an array of that data structure to represent the world. Then you use some method of displaying the array that doesn't use one GameObject for every tile. In the case of SpriteTile, it creates enough sprites to fill the screen, and recycles them as the camera moves, so it's like a "window" into the world.

    --Eric
     
  6. MoonJellyGames

    MoonJellyGames

    Joined:
    Oct 2, 2014
    Posts:
    324
    I've been trying to do as much without purchasing pre-made stuff as possible but I might have to look into it. When I'm at home (and not typing with a phone ) I'll have to share my code, and maybe you can tell me if you think it'll work with SpriteTile. I don't know how much it matters, but my game will not have a moving camera. It's supposed to be something like Towerfall, if you're familiar with it.