Search Unity

Tile Based Map Nav

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

  1. Hmtinc

    Hmtinc

    Joined:
    Aug 11, 2013
    Posts:
    6
    I was wondering if it would be possible to get this plugin to work with touch based controls.

    Oh and earlier in this thread i asked if it was possible to lock the camera to the map , I finally managed to get the script to work . So i thought I include the clamp script for anyone who may want it

    Code (csharp):
    1. transform.position = new Vector3(Mathf.Clamp(transform.position.x, xmin, xmax), 0, Mathf.Clamp(transform.position.z, zmin, zmax));
     
    Last edited: Sep 26, 2013
  2. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    The included samples use mouse clicks so if you are basing your work off that then it should work since left-click is one touch and right-click is two finger touch.

    The core system itself does not care about input.
     
  3. BenKurdziel

    BenKurdziel

    Joined:
    Nov 9, 2012
    Posts:
    8
    Hey, so here's a question for you.

    I'm creating a multiplayer turn based game using Photon's Cloud Service. In order to have an object recognized by the server, you have to use their special PhotonNetwork.Instantiate() line. With this, from what I've seen, you have to use Unit.SpawnUnit(). Both of these lines take very different arguments.

    Would you know if it is possible to Instantiate a unit using the PhotonNetwork.Instantiate() method, and then link it into the MapNav as a unit afterwards? Basically, can you link an already existing unit into the MapNav without having to spawn a new one.

    Or if you've worked with Photon and know how I can create the unit with your SpawnUnit() method and then link it to Photon, that would be great to, but I wouldn't expect you to be able to answer questions regarding other plugins.

    Thanks in advance :)
     
  4. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    After spawning a unit you need to link it to a node and map. NaviUnit.mapnva and NaviUnit.node. You also need to tell the nod that the unit is on it. NaviUnit.node.units.add(the_unit);

    How you determine which node this is, is up to your game's design. Not sure how you send data around with photon cloud but don't send the unit positions, send node IDs. This is less data than a vector and you then use this to find the node and update the specific unit's position with that. MapNav.nodes array is always in a specific order so you could use the index of the node in the array. Same a the child gameobject (node) in the parent gameobject (mapnav) in the scene.
     
  5. Morgen

    Morgen

    Joined:
    Jan 2, 2013
    Posts:
    11
    Hi, Leslie!

    After upgrading to Unity 4.2 there appeared a Log Warning about deprecated enum AnimationPlayMode.
    The full text is here:
    I tried to just remove that and can't say for sure that sothing changed in tile animation or not. And PlayMode enum does not contain something like "Mix".

    Since there is no way to know what's "Mix" purpose was (google has no answers and the only topic on this forum says nothing too), can you please give a comment about how to upgrade your script without breaking anything or maybe create patch for those who use TBMN. Thank you.
     
  6. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    It was used in conjunction with WrapMode.Once to make the animation stop properly (on the marker things).

    The animation was already playing but with wrap set to looping. So now I want it to stop but I do not want to just cut it off, I want it to reach the end. So I set wrap to once and have to call Play again for the animation to take this into account. But if I called play again it would restart the animation, no matter if it was 1/2 way through and then cause an artefact in the playback. Mix prevented this.

    It should be fine if you change the line to...

    this.animation.Play();
     
  7. Morgen

    Morgen

    Joined:
    Jan 2, 2013
    Posts:
    11
    Thank you. Looks like it works :)
     
  8. Nevulus

    Nevulus

    Joined:
    Dec 7, 2012
    Posts:
    29
    quick question: How can I center camera on a newly generated map nav of nodes?

    I am dynamically generating a grid for a small board game and would like to center the cameras position and rotation whenever a new game board grid is generated.

    I've centered the position but can't get the rotation.

    P.S. sad to see the dungeon editor asset gone from store. I had purchased it previously and lost it when I did my recent format on a new ssd drive.
     
  9. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    The "center" tile should be the one in the middle of the array of nodes. center_node = mapnav.nodes[mapnav.nodes / 2]
    With that you can then access the transform of the node to find the position, center_node.transform.position;
    As for rotation, there is not really a simple way of doing it with the sample camera scripts. You might have to create a new one. I'm not even sure how the current CameraOrbit script can be modified to support this because of the way it works.

    You should still have access to it. Go to your Asset Store inside Unity and click on the Download Manager button to see everything you own and download it from there
     
  10. Nevulus

    Nevulus

    Joined:
    Dec 7, 2012
    Posts:
    29
    I figured out a quick fix by just setting targetX and targetY on the condition of true in camera orbit update function. This will work for now since I am not working on the actual game camera for my team and just needed a temp solution.

    One other problem I am having with MapNav.cs is that nodesCache is never null, so the following makes no sense:

    for example start en empty scene, and put the following on an empty object:
    Code (csharp):
    1. public GameObject[] nodesCache;
    2.  
    3.     void Start () {
    4.         if (nodesCache == null) { Debug.Log ("Nothing to see here"); }
    5.    
    6.     }
    7.  
    in MapNav.cs you check nodesCache for null when its never null. Or am I missing something?
    wouldn't just checking nodesCache.Length be the better option?


    p.s. No, I do not have the old dungeon Editor asset in my Asset Store downloads anymore. As I stated before, I installed Unity3d on a new SSD drive and installed latest version of Unity w/ Pro license and it is not showing up on my list of purchased assets. No worries, it was my quick prototype asset for rooms in levels and never really worked that well. I just wish previous owners of the asset were at least given another option like unirpg at a reduced discount due to its similarities.
     
    Last edited: Oct 3, 2013
  11. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    The ==null was probably just sanity checking.

    You can take this up with Unity as they are in control of this. The asset should always be available to people who already purchased it. It is not supposed to be removed but only deactivated so that further sales of it can't take place. http://unity3d.com/company/contact
     
  12. Hmtinc

    Hmtinc

    Joined:
    Aug 11, 2013
    Posts:
    6
    I am attempting to add my own model of a tank into my game , but for some reason my model doesn't move around and rotate like the sample units , is there something i have to do to fix this .
     
  13. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    Looks like your pivot rotation is wrong. The forward face of the unit should be down the z-axis.
     
  14. Rampa

    Rampa

    Joined:
    Jul 12, 2012
    Posts:
    7
    Hi all,

    I bougth this awesome package a few days ago and I'm now building a simple turn based tactic game.

    Anyone knows how I could handle the AI? anyone has already built an IA for this lib?

    Any idea or ressource link would be great :)

    Thanks in advance
    Rampa
     
  15. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
  16. Rampa

    Rampa

    Joined:
    Jul 12, 2012
    Posts:
    7
    Hi,

    Thanks a lot, it helped me a lot.

    Now I have a strange issue with the GetPath function :
    When I use the 3rd parameters, the function always return null, even though there is a valid path :
    The details:
    I am using mostly the default tile type + I have added a new tile type : Cover
    Code (csharp):
    1. Cover =  0x10, // 16 Nothing can move into this tile, but it can be fired through
    2.  
    Most of the node are "Normal" only.
    In the Unit script,when I do :
    Code (csharp):
    1. TileNode[] path = node.mapnav.GetPath(node, target, TileNode.TileType.Normal);
    2. Debug.Log("path is null ? : " + (path ==  null));
    It always return null (even though there is a path)
    I also tried :
    Code (csharp):
    1. TileNode[] path = node.mapnav.GetPath(node, target, tileLevel);
    2. Debug.Log("path is null ? : " + (path ==  null));
    It also return null (which is logical since tileLevel is set to "Normal"


    If I don't use the 3rd parameter:
    Code (csharp):
    1.        TileNode[] path = node.mapnav.GetPath(node, target);
    2.         Debug.Log("path is null ? : " + (path ==  null));
    The API return a path, but it goes through wall and everything (as expected ! )


    Did I do something wrong? I don't understand where is my mistake

    Thanks in advance
    Rampa
     
    Last edited: Oct 7, 2013
  17. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    Could be that you did not set any of the nodes as being on the "normal" level in the scene? Sample 1 shows the use of these different node types/ levels with normal, water and air types. Check the "tile type mask" for the node in the inspector.
     
  18. Rampa

    Rampa

    Joined:
    Jul 12, 2012
    Posts:
    7
    Hi,

    Thanks for the answer


    I found my mistake !

    To calculate the distance and path between 2 units I'm using your function GetPath with another unit as the target

    It doesn't work because it can't calculate path between 2 units if the flag "One Unit Per Tile Only" is set to True, which is logic :)

    I created a specific function for my needs and it now works


    Thanks for your time :)

    Rampa
     
    Last edited: Oct 8, 2013
  19. Hmtinc

    Hmtinc

    Joined:
    Aug 11, 2013
    Posts:
    6
    I set my model to 0,0,0 and made the forward side face the z axis , but the model still moves around like shown in the video .So is there another way to edit the pivot point or make a prefab like the sample. oh and my prefab is made of multiple meshes , could that effect the pivot point ?
     
  20. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    Import one of the sample unit FBX files into your 3D tool and have a look at what the axis look like for it. I know in max for example if you make the model face along the z-axis you will not see the same effect in Unity. There is also a y-up (or something like that) setting in the FBX exporter that I think influences the pivot.You need to play with this until you figure out what it is supposed to look like in your 3D tool to export correctly to Unity.
     
  21. hyunil.kim

    hyunil.kim

    Joined:
    Sep 1, 2013
    Posts:
    2
    Hi Leslie,

    I am working on Unity3D game where up to 4 characters will be racing on a tile-based track. Each character has a lane assigned, and it does not travel to other lanes. Lanes have slopes and characters will be slowed on uphill tiles and accelerated on downhill tiles. Tracks are about 60x60 and there might be a bit bigger ones in the future.

    One other requirement is that the map data is serializable so I can store the data in the database, and create the actual map during runtime.

    Do you think TBMN is suitable for this? Or do you know of one that is?
     
  22. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    I do not think Map&Nav is good for this.
    The paths would not be an issue and you would basically delete all nodes not related to the "path" and just have 4 maps (paths) so each player got his own one. Problem is the serialization bit. There is nothing build in to do that for you.
     
  23. Fuzzypup

    Fuzzypup

    Joined:
    Aug 13, 2013
    Posts:
    190
    How do I contact you about questions on the software?
     
  24. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
  25. perezbalen

    perezbalen

    Joined:
    Aug 19, 2013
    Posts:
    10
    hi

    is there a way to make custom movements, like in chess?

    thanks.
     
  26. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    The build in path-finder is an A* implementation so that won;t return chess-piece like move paths.

    The core of Map&Nav is there to provide you with an easy way to find the link between nodes and includes the concept of levels (height on a tile) so that you can decide if one or more obects can occupy a specific tile depending on their "height" on the tile. On top of this it has some tools to make the placement of the nodes easier when designing a "map".

    About the only thing MapNav can help you with is having something in the scene that can be used as a reference for where the board "tiles" are so that it is easier to position a piece on it. I do not think you need something like MapNav for this. A simple array and some maths will be enough to simulate the board and figure out where to position pieces and then the rest, like determining how pieces move, would have to be coded anyway even if you used MapNav.
     
  27. hyunil.kim

    hyunil.kim

    Joined:
    Sep 1, 2013
    Posts:
    2
    Thank you very much for your response :)
     
  28. perezbalen

    perezbalen

    Joined:
    Aug 19, 2013
    Posts:
    10
    Thanks for the reply.

    is there a way to enable/disable node connections in scripts? (for example, have a bishop disable -for his turn- all nodes that are orthogonal to his location, so to hack the A* to get chess moves)?

    On another note, I saw the videos and are quite informative, but is there a tutorial on how to use Map&Nav in an actual game? (for example, how to set up the units, or how to use turns, etc)?
     
    Last edited: Oct 16, 2013
  29. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    You would have to add an On/Off Switch modifier to all nodes so that you can then turn it on or off at run time. Sample3 shows the use of this modifier component on some of the nods of that sample's map.

    There are 7 sample scenes that you can have a look at. There is no written or video tutorial on how to setup a unit or turns cause the "units" and turns thing is not part of MapNav core system, they are part of the samples.
     
  30. DonJaket

    DonJaket

    Joined:
    Oct 14, 2013
    Posts:
    10
    Hello Leslie,

    Is there a way to draw a grid on the terrain, similar to what Civilization and other 4x games do?

    $ss_84ee7ab3b0148a260359f8d5a78a2ab9033aa695.1920x1080.jpg
     
  31. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    MapNav handles the invisible grid nodes only. It is not meant to be used to draw grids.
     
  32. yaciam

    yaciam

    Joined:
    Oct 15, 2013
    Posts:
    1
    Hi
    I purchased your asset yesterday but when i create a new Mapnav it gives me that error even in a complete new project:

    NullReferenceException: Object reference not set to an instance of an object
    MapNav.CreateTileNodes (UnityEngine.GameObject nodeFab, .MapNav map, TilesLayout layout, Single tileSpacing, Single tileSize, TileType initialMask, Int32 xCount, Int32 yCount) (at Assets/Tile Based Map and Nav/Scripts/TMN/MapNav.cs:295)
    MapNavCreateWindow.CreateMapNav () (at Assets/Tile Based Map and Nav/Editor/MapNavCreateWindow.cs:76)
    MapNavCreateWindow.OnGUI () (at Assets/Tile Based Map and Nav/Editor/MapNavCreateWindow.cs:57)
    System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)


    and I can't figure how to solve that probleme can help me plz?


    edit: the part of the code it reference to is :

    // update TileNode component
    TileNode n = go.GetComponent<TileNode>();
    ---------> n.idx = count;
    n.mapnav = map;
    n.tileTypeMask = initialMask;
     
  33. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    Seems like you did not specify a valid Tile Node prefab. Sample nodes can be found in \Assets\Tile Based Map and Nav\Prefabs\tile_nodes\
     
  34. perezbalen

    perezbalen

    Joined:
    Aug 19, 2013
    Posts:
    10
    That´s good to know, because your videos seem to imply otherwise.

    I browsed your site and couldn't find a manual, and I understand there are sample scenes in that I can study (but I won't be able to study them until I buy the asset). An the thing is that most of the reviews in the asset store imply that the documentation is lacking, and that it takes a lot of time to figure out the workings of the tool (for instance, one reviewer wrote "The API is undocumented and althought there are tutorials on how to use it in the editor... there are ZERO tutorials on how to use the api for something as simple as asking a unit to move from tile...").

    The review that raised a flag for me was this one: "...when I buy an asset is because I want to cut off some development hours, not because I want to spend many hours trying to understand some code I didn't write neither modifying it."

    While the tool seems great, and seems to do what I need, the thing is that ´m not the best coder, so the question that plagues me is "will I be able to use it"?
     
  35. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    The "documentation" is in the code .I feel it is pointless to repeat what is in the comments when you have the full source in front of you, but that is just me. If that is not gonna work for you then this kit is not for you. Also keep in mind that this is not a turn based kit but code to handle something specific (make access to a grid of nodes easier) so don't expect turn based game mechanics and all that outa of the box. There are samples of how to move units and all that and it might look like a full kit but they are just samples and not as complete something you would expect in say, a turn based strategy game kit.

    from NaviUnit
    Code (csharp):
    1.  
    2.     /// <summary>
    3.     /// Move the unit to the specified target node. Will make a callback with
    4.     /// eventCode=1 when done moving if a callback was set in Init()
    5.     /// iTween (free on Unity Asset Store) is used to move the Unit
    6.     /// </summary>
    7.     /// <param name="map">NavMap to use</param>
    8.     /// <param name="targetNode">Node to reach</param>
    9.     /// <param name="moves">
    10.     /// Number of moves that can be use to reach target. Pass (-1) to ignore move limits.
    11.     /// The unit will move as close as possible if not enough moves given.
    12.     /// ref moves = (moves - actual_moves_use) on return (thus moves left); or if moves = -1 passed, it will be set to number of moves that will be taken.
    13.     /// </param>
    14.     /// <returns>True if the unit started moving towards the target</returns>
    15.     public bool MoveTo(TileNode targetNode, ref int moves)
    16.  
    17.  
    More that that and I could just as well create a game maker or tutorial on how to create a specific game ;)
     
  36. Middy

    Middy

    Joined:
    Jun 19, 2013
    Posts:
    4
  37. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
  38. vonpixel

    vonpixel

    Joined:
    Oct 2, 2012
    Posts:
    31
    Hello!

    I just purchased your framework, and im running through the demo scenes in a new fresh empty project (only other thing loaded is playmaker)- and I can't get any of the scenes to run? Unity tells me all the compiler errors must be fixed before entering play mode.
     
  39. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    Post the error message(s) you are getting.
     
  40. vonpixel

    vonpixel

    Joined:
    Oct 2, 2012
    Posts:
    31
    The error is

    Assets/iTween/iTween.cs(46,14): error CS0101: The namespace `global::' already contains a definition for `iTween'

    I am still quite new at this though. I've figured out that its happening from importing another package that also uses iTween.
     
    Last edited: Nov 7, 2013
  41. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    You have two or more copies of the same scripts of iTween in the project. Remove the extra iTween.cs script
    Map&Nav has the script in \Assets\Tile Based Map and Nav\Scripts\Common\ if you want to remove it or replace it with a newer version.
     
  42. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    You have two or more copies of the same scripts of iTween in the project. Remove the extra iTween.cs script
    Map&Nav has the script in \Assets\Tile Based Map and Nav\Scripts\Common\ if you want to remove it or replace it with a newer version.
     
  43. Kintaro

    Kintaro

    Joined:
    Jul 9, 2012
    Posts:
    2
    Hello
    I think create two lists (player and enemy)
    is it possible to create a zone of spawn for the player and enemy units?

    Thank you very much
     
  44. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    There is no build-in feature to handle spawning, except for the samples which uses a random spawn. You could keep two lists of nodes and via inspector populate them with the nodes that the player and enemy can spawn in. The other option is to say the player spawn in the lower 1/3 and the enemy the upper 1/3 and then you simply use an offset into the nodes list in mapnav.nodes to choose an upper or lower set of nodes.
     
  45. vonpixel

    vonpixel

    Joined:
    Oct 2, 2012
    Posts:
    31
    Hey!

    Been using this for awhile now prototyping an idea that im starting to take further.

    Got a few questions!

    How would you recomend going about having diagonal moves on the 8 axis square tiles take up 2 move points?

    Also- im curious what you would think about adding larger units to the grid- i.e units that take up 4 squares (in the center) and other odd shapes? Unless this is something i should be lookin' at with the tile markers?

    I thought about using a second grid of larger tiles, but you loose the fine tuning of a dense grid for movement.
     
  46. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    The path finding code does not take diagonal into account when calculating movement and you would have to modify the function to do so, if you use that function (use by the NaviUnit and sample units for movement).

    A nodes neighbours will have to be checked to see if they are diagonal to it or not. All nodes are added as neighbours in a certain order.
    TileNode.nodeLinks[] contain the neighbours for a node after MapNav.Start() was executed. Linking the nodes (deciding who are neighbours) happens at MapNav.cs line 307 (LinkNodes()).


    For 8-square it is ...

    0: previous node
    1: next node
    2: prev row, same column
    3: next row, same column
    4: prev row, prev column
    5: prev row, prev column
    6: prev row, next column
    7: prev row, next column

    As for bigger units, the system does not support this and you will have to modify the code for it. One thing that should be done is to link nodes with the unit occupying them, especially if you want to use the build in path finder which needs to know where units are. NaviUnit.LinkWith() line 104 NaviUnit.cs is used to link with nodes. TileNode.units contain the links with units on it (more than one can occupy a tile, for example land and air unit).
     
  47. vonpixel

    vonpixel

    Joined:
    Oct 2, 2012
    Posts:
    31
    Very helpful- thank you very much.
     
  48. Jayray

    Jayray

    Joined:
    Apr 23, 2013
    Posts:
    1
    Hi Leslie,

    I just wanted to thank you for this awesome package. I was about to build this from scratch, but after seeing the feature set this will save me so much time. I can see so many ways to reuse this package for many different game projects.

    thank you :)
     
  49. Baconshot

    Baconshot

    Joined:
    Dec 21, 2013
    Posts:
    3
    Hey Leslie

    Have you had any response or feedback, regarding the "TileNodes Create Tool"? When I follow your tutorial on http://www.youtube.com/watch?v=ZjAU0AbA0aQ and I try to click the "create" button, nothing happens. Whether I try to use one of your test scenes or a new scene from scratch.

    Thanks in advance. :)
     
  50. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    Is the TileNode Prefab set? You are not getting any error messages in the console?