Search Unity

Pathfinding and Assigning Info to Hex Tiles

Discussion in 'Navigation' started by intuithue, Nov 6, 2017.

  1. intuithue

    intuithue

    Joined:
    Oct 9, 2016
    Posts:
    3
    Hello, everyone! I'm fairly new to programming and am looking to implement pathfinding and other features based around the hex-tile map I've just started setting up (for a turn-based RPG like Final Fantasy Tactics). In the past, I've generated the tiles via code, but this time, I decided to hand-design the map (and have the hexes all sorted under one empty game object), so I'll need a solution that can be applied over this.



    Is there any clear way to take each of the existing hexes, find its center, and assign all of the centers as nodes to some sort of mesh to use for pathfinding (where players can move a certain number of spaces per turn)?

    Long-term, I am seeking a solution where I can also easily define attributes for the tiles such as their type (sand, grass, swamp ..), whether they are passable, height, combat/other modifiers, chance of spawning loot, and the like. I am imagining that there is a fairly straightforward way to approach this, but I am just entirely unsure where to start, with very little knowledge of setting up nodes or meshes or anything.

    If anyone with more experience can point me towards a solution (even if it's just tutorials on YouTube or concepts to explore), that would be greatly appreciated.
     
    Last edited: Nov 6, 2017
  2. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    708
    I have an idea but I'm not sure how well it'll work for your situation. Build a general navmesh for your area the navmesh will only be what takes care of The Locomotion from point A to point B. For each hex now set a tag of something like walkable hex.

    https://docs.unity3d.com/ScriptReference/Physics.OverlapSphere.html

    now say once it's the players turn you'll casting overlapsphere of movement radius and every hex grid piece that is within this radius will come up as an option to move to
    Now just have your navmesh agent .set destination hex grid piece position.

    This is just the basic idea of how it work if you need a little bit of help with the scripting and of it let me know and I can whip up a quick very basic script that should get you up in running at least at a minimal level
     
    Last edited: Nov 7, 2017