Search Unity

Guidance needed. Grid based movement?

Discussion in 'Navigation' started by Tarodev, Aug 13, 2015.

  1. Tarodev

    Tarodev

    Joined:
    Jul 30, 2015
    Posts:
    190
    I am wanting to make a turn based, tactics style game that works on a grid system. I have dabbled with A* path finding project but am wondering if there is a better, cleaner method for achieving what I want.
    As I'm very new, I have no idea if I'm doing this the best possible way, but at the moment I have the floor made up of separate cubes, which I have OnMouseEnter/Exit script to highlight the square, with A* pathfinding over the top.

    Here is a screenshot of how A* Pathfinding project calculates the course (in red) and how I ultimately want units to move (in green).

    My question: Is there a better, cleaner and simpler way to make mouse selected grid movements? I don't mind if it's using an asset or writing code from scratch. As long as I have a solid direction I can work towards it.
     

    Attached Files:

  2. CastleIsGreat

    CastleIsGreat

    Joined:
    Nov 10, 2014
    Posts:
    176
    Hmm well, just a rough idea would be to set up a node based network for every grid spot, and then have an object follow your mouse and find out which node is closest to your mouse, and when you click it would move the object to that node's location.
     
  3. Shbli

    Shbli

    Joined:
    Jan 28, 2014
    Posts:
    126
    NavMesh agent doesn't look super good to me for GridBased navigation

    There are some in unity3d assets store, but I would say it will be easy to create a custom one

    Search and look at YouTube how to create a grid based system in Unity3D
     
  4. Lahzar

    Lahzar

    Joined:
    May 6, 2013
    Posts:
    87
    If you use a good A* system, like The A* Project by Aron Granberg, you can code in a system which gives a cost to nodes based on length. So paths made up of shorter paths would get a higher cost, while paths made up of less longer paths get a lower cost. Something which would apply a higher cost to jaggered paths, understand?

    You would also need to tweak it so your AI won't take massively longer paths instead of the shortest path etc. You get the idea!