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. Dismiss Notice

Best way to move to make a top-down tile based game and support only up/down/right/left movement?

Discussion in '2D' started by Punfish, Dec 25, 2014.

  1. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    327
    I've been working a bit with Tiled to design the levels on a top-down game. The problem I'm facing mostly is how to make a character avoid collision and to not move diagonally. I provided a screen capture for clarity.
     

    Attached Files:

  2. rabirland

    rabirland

    Joined:
    Nov 22, 2014
    Posts:
    29
    Loop throught the path it gives to you, and if it find a collision start to search an alternate way... If it works in those blocks, you might use them only for pathfind not the entire unit system... In my knowledge Unity doesn't have 2D pathfinding yet... You have to implement yours...
     
  3. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    327
    I actually attempted something similar before I got to your post. Character moves on X axis until it hits a wall or at destination then moves on Y axis until at destination or hits a wall in which it just repeats. Although, this could be problematic for crevices, if you were to path into a C shaped object for example.

    What do you mean by only using specific blocks instead of the entire system?
     
  4. rabirland

    rabirland

    Joined:
    Nov 22, 2014
    Posts:
    29
    I mean using blocks that you use the Square shaped steps on the pic, not the float values ofthe transform...
    I mean not "Transform.position" but "Map[i , j]"
    Also you need pathfinding... Try a recursive method...
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    There's a grid move script here. You can do collision by using an array lookup for tiles that are defined as passable or not passable. (Example)

    --Eric
     
  6. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    327
    It's really hard finding tutorials and examples for 2D layouts. I'm not really deep into my project yet. Would it be worth just learning to make a top-down game with the 3D editor?