Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Tile Based Map Nav

Discussion in 'Assets and Asset Store' started by Leslie-Young, Jun 2, 2012.

  1. Anymeese

    Anymeese

    Joined:
    May 27, 2013
    Posts:
    20
    Just bought the asset. Very useful, great job! One question though: Is there a script or anything for getting one or all adjacent tiles? Specifically hexes for my situation
     
  2. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    You can use the nodeLinks array to find out what the neighbours of a node is.
    See TileNode.nodeLinks
     
  3. Anymeese

    Anymeese

    Joined:
    May 27, 2013
    Posts:
    20
    Whenever I try and use this I get an error..

    Simply making a script with a public TileNode var and dragging/assigning one from the mapnav to the script, and in the script have in Start to Debug.Log(node.nodeLinks.Length) gives me a Null Reference Exception error
     
  4. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    You can't do it in Start since the map is initialised in Start.
    Wait a frame and then try to access it.
     
  5. Anymeese

    Anymeese

    Joined:
    May 27, 2013
    Posts:
    20
    That fixed it, thank you!

    Another issue: Every single time I save/compile my scripts with f5, I get 3 "Default Parameter Specifiers Are Not Permitted" errors in RadiusMarker.cs for Show, ShowAll, and ShowOutline. How can I make this error go away without messing up anything in your scripts?

    EDIT: Also I'm having issues catching a raycast (mouse over) on a TileNode. I show/enable the mesh and collider with the tilenode.Show() function, then for some reason doing the raycast the exact same way as in your scripts does not let me detect when I'm mousing over the shown mesh. I'm trying to get the mesh to play its animation (flash) when moused over

    Thank you for your help btw :) It's a great asset
     
    Last edited: May 31, 2014
  6. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    Strange that I never picked up on that error message. What version of Unity are you using this with?
    Anyway, it can be fixed by removing the default params from the mentioned functions.
    For example,
    public void ShowAll(bool adaptToTileHeight = false)
    should become
    public void ShowAll(bool adaptToTileHeight)


    Not sure how to help with your second problem. Check that the layer the node is in is set correctly and that you are using the correct layer mask in your raycast.
     
  7. Anymeese

    Anymeese

    Joined:
    May 27, 2013
    Posts:
    20
    I'm using Unity 4.5 or whatever the newest version is. I just reformatted my computer a couple days ago and was running 4.3 prior to the reformat, and never had the issue. It may be the different version of unity, or it may be some other setting being reset
     
  8. mizak

    mizak

    Joined:
    Jun 5, 2014
    Posts:
    14
    Hey, I bought this asset and i've been working with it for a little bit but I can't figure out how you setup your samples. I've tried creating my own terrain and following your video to use the height tool to put the mapnav on it. I put the game controller script in the scene as well but I still don't see any units. The basics are what i'm having trouble understanding.
     
  9. EstarCream

    EstarCream

    Joined:
    Feb 22, 2014
    Posts:
    6
    Hi, I've just purchased your excellent product yesterday and have somewhat successfully integrated your tile and navigation system into my project.

    Is there any way to calculate the movement cost between 2 nodes?
    This is taking into account movement modifiers and obstacles. For example calculating the path over 2 nodes, both with a movement cost of 3, will return a value of 6.

    I could only find the method TileNode.TileCountTo() but this only counts the number of nodes in a path while ignoring movement modifiers and obstacles. So using this method on a path of 4 nodes that includes a node that cost 2 movement points will give a value of 4 instead of 5.
     
  10. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    You will have to open the example scenes and look at how I add units to the example controller scripts if you want to use them. Study the inspectors for the controllers and the code of the sample controllers. I do not recommend building your game on my example controllers though. They are only samples, showing some possible ways of spawning/ placing units on the grid and all the steps involved if you want to make use of the included sample 'unit' scripts.
     
  11. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    It will require some checking of the tile modifiers. There is no one function to do this. Check out the MapNav.GetPath to see how I check if a node will cost more to move over.
     
  12. EstarCream

    EstarCream

    Joined:
    Feb 22, 2014
    Posts:
    6
    Hi, Leslie

    Thank you for the quick reply!!

    I've looked into the MapNav.GetPath method and have created my own function to calculate the movement. Adding the number of nodes in the returned GetPath() nodes array with the extra movement cost of the nodes within the array did the trick!
     
  13. DrunkReaperMatt

    DrunkReaperMatt

    Joined:
    Feb 11, 2013
    Posts:
    38
    do you have any support planned for unity 2D. I plan to use your product mostly for 2D work.
     
  14. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    Sorry, there are no plans to add 2D support.
     
  15. ProgenitorVirus

    ProgenitorVirus

    Joined:
    Jul 15, 2014
    Posts:
    2
    Is there any built in functionality to handle the height difference between tiles in terms of a movement modifier?

    I would like to modify characters' movement such that when traveling to a TileNode that is higher than another, it may take more movement points to 'jump' up there.

    I'm thinking that TNEMovementModifier.cs may do the job, however I'm not sure it is set up to be used in such a way (or if it would be practical). I'm thinking I may have to add say, a tileHeight property to TileNode.cs, but wanted to hear your take on this before I go mucking up the code ;)
     
  16. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    There is only a way to disable the links when the height difference is too big. You might want to look at at that part of the editor code to see what I did there and then add your own option that uses the movement modifier. Have a look at 'auto-link setup' at bottom of the map inspector. That is what I used to disable links between nodes in sample 3.
     
  17. ninchik

    ninchik

    Joined:
    Jul 31, 2014
    Posts:
    2
    hi Leslie,

    Just bought your plugin, very nice! I'm only new to unity so this plugin makes design way easier. The only bits I'm not sure about yet are how to place the units on the map nav manually and configure them to have the moving platform like you did in the sample scenes. I'm also trying to create my own units and as I understand it should be a prefab that contains a mesh and texture for my unit as well as Unit script which it can be controlled by, I created my object in blender but can't seem to get it to show up as a unit for your plugin, any ideas/tips??
     
  18. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    Units are "placed" via code because you need to link them to the nodes they stand over.

    I'm not sure what moving platform you are referring to. Which sample number is that?

    Can you import your Unit into Unity and drop it into a scene with it showing up properly?
     
  19. ninchik

    ninchik

    Joined:
    Jul 31, 2014
    Posts:
    2
    ok, so you wouldn't recommend placing units manually or can it be done at all, so far I can put a unit on map nav and can click it but don't see the neighbouring cells -- the marker which highlights the available movements (that's the moving platform i was referring to). As for the Unit I'm not sure how to create that, if I create a new prefab and add my object to it (created in Blender or Maya) and add in the Unit and Sample Weapon scripts to it, if I then add it to the unit fabs array in GameController script, the unit is spawned but not showing up the range marker.

    Overall, what I want to do is change the shape and texture of units with my own ones and place units non-randomly over the scene, so that their ranges don't intercept. I guess I could just swap out the mesh from the existing units to my own meshes and in the GameController script assign individual preset positions for each unit?
     
  20. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    The thing is the Unit needs to know on what Node it is, else the movement range marker and the build-in path finding, for example, will not work.

    I would create a kind of spawn point script that can take a node and a unit that needs to be spawned. This can then create the unit and make the calls to the node script to link the unit and the node with each other. See my sample controller on how I spawn units.

    This spawner could even work such that you place it over a node and it will at runtime cast a ray down to see what node is hit and then automatically know what node it should spawn the unit on.

    The major thing is that nodes and units should be "linked" when a unit is sitting idle on a node.
     
  21. ProgenitorVirus

    ProgenitorVirus

    Joined:
    Jul 15, 2014
    Posts:
    2
    Hi again,

    I'm having some difficulties getting the TNEMovementModifier to apply to the Unit's actual moves (currMoves in your sample Unit). Essentially, while the movement modifier is being used to calculate available tiles properly, it does not remove the modifier's value from the Unit's currMoves. As an example, here is what I mean using the provided sample01 scene (currMoves highlighted at the bottom of inspector):





    So, as you can see, moving to that rough patch should take 2 moves, and the unit should then be unable to travel to the adjacent rough patch (as the tile takes 2 further moves). Since currMoves isn't being updated though, the unit is free to move not only to the adjacent rough patch, but also past it one more space. Though the unit has 3 moves per turn, it is effectively allowed to make 5. Any insight on this would certainly be appreciated!


    [EDIT]
    I managed to fix this myself after a bit of digging into the code.

    While I can't be sure of elegant code, I just ripped the bit of GetPath(...) in MapNav.cs which goes through the TNEMovementModifier and placed it into _GoToNextNode() in NaviUnit.cs, created a virtual OnMovementModifier(int movesModifier), and overrode in Unit to subtract the movesModifier from the moves. Hindsight is always 20/20 I guess, the solution was rather simple in the end.
     
    Last edited: Aug 10, 2014
  22. W1ntermute

    W1ntermute

    Joined:
    Aug 24, 2014
    Posts:
    9
    Thank you for your asset!
    Do you have any plans for adding multi-tile units (2x2, 3x3, etc)?I have some thoughts how to implement 3x3, but it's not clear to me how is it possible to create 2x2 units for example , because its "center" will be situated "between" of nodes (in the center of square of 4 nodes).Looks like we need to create another grid, specially for units which consist of even number of tiles.
    Sorry, if this question has already been asked.
     
    Last edited: Aug 24, 2014
  23. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    No, there are no plans to extend on this asset's current features.
     
  24. rayfigs

    rayfigs

    Joined:
    Feb 8, 2009
    Posts:
    41
    Hi Leslie,

    I picked up tile nav in hopes that I would be able to recreate this simple flash game.
    http://www.cybersalt.org/games/cat-herding

    I'm very new to unity. Could you suggest anything for me to research in order to recreate this? Would plybox be of any help here?

    Thanks
    Ray
     
  25. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    The package includes various sample scenes and sample scripts you can look at to see how to interact with the Map&Nav API.
     
  26. ali_farooq

    ali_farooq

    Joined:
    Sep 8, 2014
    Posts:
    18
    how we can extract or restrict the specific part of map in mapnav like if we only want to take the map of England specific town or city. so i have a problem that how and which algorithm we use in unity 3D development to extract only specific area or town map in our mobile application.
     
  27. ali_farooq

    ali_farooq

    Joined:
    Sep 8, 2014
    Posts:
    18
    how we can extract or restrict the specific part of map in mapnav like if we only want to take the map of England specific town or city. so i have a problem that how and which algorithm we use in unity 3D development to extract only specific area or town map in our mobile application.
     
  28. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    The tool does not support turning off specific sections at runtime.
     
  29. zebboz

    zebboz

    Joined:
    Oct 18, 2014
    Posts:
    2
    Hi,
    I just bought your Tile Based Map Nav asset. I have a lot programming experience but haven't done much with Unity. Seems promising asset for me so far but I have problems working with maps, so here goes:

    1. Could you provide more information how to do for example hex map from scratch using thingies provided in the asset? I've watched the video in first post in this thread and I experimented with that 'New MapNav' dialog. It creates MapNav with nodes & connections ok. But how I can add the actual terrain tiles after that? I would like to get end result that would be quite similar as in example Sample 3.

    2. Talking about Sample 3: If I want to change height of one node, let's say from tile_h1 to tile_h2. How it is done?

    BR,
    zebboz
     
  30. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    Map&Nav is not for laying out the tiles. It is the invisible grid of nodes that you use to for example moves units around.

    For the examples (from the one that is a simple plane, to the one that has a mesh based terrain) I first created the terrain/ floor with proper collides on and then generated a mapnav and used the mapvan inspector tools to align the nodes over the terrain. floor.
     
  31. zebboz

    zebboz

    Joined:
    Oct 18, 2014
    Posts:
    2
    Ok. So tiles are just graphical presentation of terrain and not needed for grid or game logic.

    So I guess answer to my 2nd question would be like "delete h1 tile and replace it with h2 tile and move the grid node a bit up".
    For new maps the inspector tool is surely the way to go as you suggest.

    Thanks for quick answer!
     
    Last edited: Oct 22, 2014
  32. Thrieu

    Thrieu

    Joined:
    Oct 28, 2014
    Posts:
    4
    There are always some projectors not working when playing the scene. They are disabled in the inspector, why?
    upload_2014-10-29_21-16-35.png
     
  33. psypol

    psypol

    Joined:
    Dec 20, 2013
    Posts:
    25
    Hello, just bought the plugin yesterday
    as a non developper but game designer i try to wire scripts to my needs and plan to take control of them with PlayMaker schematics.

    i managed to force the camera to follow a unit i did not clicked-on (my player avatar)
    now i have a problem : in the script "gameControler" i would like to force which unit is Unit selectedUnit
    (my goal is to display the possible moves of my avatar without the need for player to initially CLICK on it)

    Feeling adventurous^^ i tried this :
    public GameObject ForcedselectedUnit = null;
    public Unit selectedUnit = null;


    and wanted to do this :
    public override void Start()
    {
    Unit selectedUnit = ForcedselectedUnit;


    but i got obviously an error on compile :
    Assets/Tile Based Map and Nav/Scripts/Sample/GameController.cs(61,22): error CS0029: Cannot implicitly convert type `UnityEngine.GameObject' to `Unit'

    simple question : how can i do to force the value of selectedUnit to what i want ?

    thanks
     
  34. Wrensi

    Wrensi

    Joined:
    Sep 26, 2014
    Posts:
    2
    Hello,

    Anyone have any ideas on how to customize the movement of units so that say they can only move to spaces 3 tiles away? Or only move in diagonals like a bishop in chess?

    Feel free to PM me if you need a better explanation of what i'm trying to accomplish

    Thanks.
     
  35. psypol

    psypol

    Joined:
    Dec 20, 2013
    Posts:
    25
    go on a unit prefab and set the value of the parameter called "Max Moves"

    P.S : anyone can help with my problem ?
     
  36. psypol

    psypol

    Joined:
    Dec 20, 2013
    Posts:
    25
    another question on my side :
    an annoying thing for user experience : when my cursor is over 2 tiles in the same time :
    the selected tile is very often the further one (as on my image the black arrow points the
    tile that the code considers to be Hoovered)
    Is there a way to fix this and always select the tile on TOP ?

    thanks for any help you could provide.
     
  37. Wrensi

    Wrensi

    Joined:
    Sep 26, 2014
    Posts:
    2
    That isn't actually what i'm looking for. That will let me set the max number of spaces a unit can move but I am trying to have it so it will only be able to move a specific way, such as it can only move to a tile 3 spaces away, so it would only have 1 move but the distance is farther than 1 tile.
     
  38. Thrieu

    Thrieu

    Joined:
    Oct 28, 2014
    Posts:
    4
    1. Would you implement Vector2 to describe a tile?
    2. Do you think it is posible to write a method to get a TileNode by a world position(find the nearest tile)? It may bring a better performance than MeshCollider.
     
  39. Thrieu

    Thrieu

    Joined:
    Oct 28, 2014
    Posts:
    4
    What is the best way to extend TileNode? I'd like to avoid modifying TileNode.cs, because this file may be changed when updating TMN.
     
    Last edited: Nov 6, 2014
  40. Harry3D

    Harry3D

    Joined:
    Jun 27, 2012
    Posts:
    29
    Hi guys!

    Leslie, great job, amazing system you got there, and also great job updating it based on the feedback people gave here. Also, you guys are coming up with some nice implementations of the system, congrats!

    I'd like to know if the limitation of 50x50 tiles per map is still on. Honestly, it already gives me a good much to work with on my current project, but it would be nice to expand the possibilities on future games.

    Also, has someone tested the perfomance on mobile? Is it optimal?

    Thanks!
     
  41. psypol

    psypol

    Joined:
    Dec 20, 2013
    Posts:
    25
    any toughts on my questions from ovtober30 and november1 ?
     
  42. KingBlackToof

    KingBlackToof

    Joined:
    Nov 22, 2014
    Posts:
    4
    Oh hello there,

    I could use some super duper help on how to identify what node an enemy Gameobject is on.

    I am trying to find the nearest enemy to a gameObject.
    I shoot out a RayCast, it hit's a target, so I have a know it's there.

    Is there a way I could use that info to find which node they are on?

    Since I expect then, I could begin travelling towards that node.

    Thanks a bunchy! :)
     
    Last edited: Nov 30, 2014
  43. EstarCream

    EstarCream

    Joined:
    Feb 22, 2014
    Posts:
    6
    @KingBlackToof
    1. You could cast a RayCast down (if the enemy is positioned above the nodes) from the position of the enemy to see if any nodes are hit.
    2. If you have a reference list of all the nodes (the MapNav script contains a "nodes" list), you can iterate through them and get the closest node to the enemy in terms of distance.

    The way I do it is that every character in my game has a reference to the node they are on. The referenced node is updated every time they move (Characters move by clicking on nodes).
    --------------------------------------------------------------------------------------------------

    Anyways, I have an issue with the Tile and Nav system.

    When getting paths to nodes the system does fine. The problem is with the actual movement path characters take to get to a target node. Sometimes they will take totally invalid paths (Issue 1). Also, it seems that characters will not take the path with the lowest cost (Issue 2, also an invalid path).

    Examples:
    Blue tiles are possible move tiles. The green highlighted tile is the destination tile.

    ISSUE 1
    Characters will take invalid paths to get to a destination tile.
    Current path the character will take to the tile:

    The character moves through the mountain tile to the south which shouldn't even be possible.

    These are the possible paths I expect the character to take:


    ISSUE 2
    Characters will not take the path with the lowest cost
    Current path the character will take:

    The character has 3 movement points. The mountain tile to the south cost a full 3 points of movement (using MovementModifier to add extra cost). The movement path the character takes should not even be possible. Also, the character has taken the path that cost the most movement points.

    Path I expect the character to take

    This is the path with the lowest move cost (and the only possible path).

    Is there a way to make characters take the path with the lowest cost? I've tried playing around with and modifying your code, mainly the MapNav.GetPath method, but all my attempts have failed.
     
  44. EstarCream

    EstarCream

    Joined:
    Feb 22, 2014
    Posts:
    6
    I've fixed my issue.
    Characters will now take the shortest path while moving. Had to write my own GetPath method that gets the shortest path between 2 tile nodes (including movement modifier cost).
     
  45. Thrieu

    Thrieu

    Joined:
    Oct 28, 2014
    Posts:
    4
    Hi, Leslie, could you please reply me? Don't abandon your users.

    I have another question: Can decal system be used for rendering highlighted tile?
     
  46. EstarCream

    EstarCream

    Joined:
    Feb 22, 2014
    Posts:
    6
    The asset has been removed from my downloads / account and I came online to discover that it has been replaced with a new version that that I need to pay for, even though I already purchased a previous version. What's going on?

    Maybe V2 is a separate asset and the previous Map Nav version was removed from the store by mistake?
    If you intended for the new version to replace the old Map Nav, then I take it that support for the version I purchased is discontinued?
     
  47. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    Sorry for late reply!! I do not visit this forum often and rely on the email notifications system to tell me when there are new posts in this thread. The forum only notified me about this last post by EstarCream and none of the ones during December o_O

    MapNav 2 is a new product and I've asked that sales of the old one be disabled. Seems like when Unity disabled it that they have to remove the package, even for people who purchased before. I do not like it either, but that is how it sees to work :(

    If anyone have a question about either version, please use my support forum at, http://forum.plyoung.com/c/mapnav
     
  48. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    847
    There's a MapNav 2 now? Oh, joy! :D
     
  49. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    How about opening the source of the original version so that the people who supported you for v1 can get the last version instead of it disappearing completely without notification.
     
  50. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    You can contact me with your invoice number and I will send you the package if you misplaced it.

    Keep in mind that it is cached on your drive (if you did not format in the meanwhile) and can be found under.
    Windows: %APPDATA%\Unity\Asset Store\PL Young\
    OSX: ~/Library/Unity/Asset\ Store/PL\ Young/