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

Need help with tile based movement for a 2d strategy game

Discussion in 'Scripting' started by dusthound, Mar 5, 2020.

  1. dusthound

    dusthound

    Joined:
    Sep 18, 2018
    Posts:
    98
    I am working on a 2d strategy game for a school project and need some advice on how to code a tile based movement system. I have a system in place that allows the player to see where a specific unit can move when clicked on. I got this to work by showing UI sprites that mark the spaces the unit can move to when the unit is selected. Other than that, I have nothing else and am not sure how to code the movement. Any ideas?
     
  2. FlashMuller

    FlashMuller

    Joined:
    Sep 25, 2013
    Posts:
    449
    That's a pretty general question.
    I would 1st look into A* path finding to define a route and then worry about moving along the found path (which is just interpolating between every tile our path is made of)
     
  3. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583


    If you want to interact with these grids I would place colliders on each tile and use a raycast from the camera to the mouse position and detect the colliders by tag or something then you can have some code fire off on a mouse click depending on where you press, should get you started. Since it's a school project I imagine you won't have much time to implement stuff so I wouldn't do anything too complicated like the A* algorithm because that would take a long time to learn just by itself.
     
  4. dusthound

    dusthound

    Joined:
    Sep 18, 2018
    Posts:
    98
    Funnily enough, I was able to get the movement system working about 10 minutes after posting this. Thanks anyway though.
     
  5. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    lol that's pretty much standard procedure for programmers when they have a problem, done it myself numerous times.