Search Unity

Tile Based Map Nav

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

  1. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    Yes, that is the process and what I did in my own turn based game.
    Check one of my previous posts for a link to that game's source code. I've also attached the editor sripts here in case it is useful. It incl. code I used to spawn my tiles, in a hex layout, so I did not have to place them manually but only move around in groups.
     

    Attached Files:

    Last edited: Dec 30, 2012
  2. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    Links between nodes in the same map can only be turned off, not deleted. Nodes of different maps can only be linked with the TNEForcedLink component (this is done when you click Create Link).

    Can you describe how you "unlink the original" and what this 'original' is? Explain in terms of node A,B,C and which are on the same map and not. Maybe then I'll know better what the problem might be.
     
  3. ronalmb

    ronalmb

    Joined:
    Dec 28, 2012
    Posts:
    4
    Hello

    EDIT: I have since made some headway with this issue, but I am going to leave this here for others that may purchase this and be similarly confused. At the end of the post is the solution I have discovered for this. Please consider commenting that the the video is no longer up to date and is better as an illustration of what MapNav does than a tutorial on getting things going -- I really like what I suspect this will do for me, but the initial hurdle of just getting it to load up was a little frustrating.

    I purchased this because I like what it may be able to do for me - assuming I am able to get what I want done with it. I am using Unity 4.0.0f7 Indie on Windows 7. I have set Layer 20 to tile and 21 to unit. I am able to load up all of the scenes and see them perform properly.

    When I go to Window -> MapNav -> New MapNav, I get the window that allows me to assign the TIles Layer (I choose tile), set width x length to 10 x 10 and then click Create MapNav. The mapNav appears in the heirarchy but I see nothing in the scene window even after focusing on it. I can see the scale, translate, and rotate pivots but the actual mapNav, points, and tiles do not appear to be visible. I have the layers set to be visible. I'm not certain what I have missed, but given my newness to Unity and this, I am sure I am missing something.

    I've attempted to follow the steps in the YouTube Video tutorial but the New MapNav window doesn't match the video. New items are TileNode Prefab and Initial Tile Mask. I believe I need to do something with this, but I'm not certain what yet. The .pdf says that it is the prefab for each marker node. I've attempted to assign both marker hexes, change up the width and length and it's not performing the way it's supposed to.

    EDIT: When creating a New MapNav, you must be sure to select a GameObject to attach to the TileNode Prefab if you wish for it to be visible like in the Tutorial videos. I started with a Hex (6 neighbor) Tile Layout and chose several of the wrong hex objects before choosing the correct TIleNode_Hex (The .pdf does point this out - I clearly missed it). If you are having trouble getting your MapNav to appear, this is the issue.

    Thank you and happy holidays.
     
    Last edited: Dec 31, 2012
  4. Ycromix

    Ycromix

    Joined:
    Jan 1, 2013
    Posts:
    2
    Man I just bought this and by studying your code I found it really great
    I just have a question to solve a problem here, maybe a bug, maybe some wrong adaptation I made...
    Is it normal for the 'units' variable containing the units in a TileNode to become null... not a List with 0 indexes? The stragest thing is that it does not happens all the time I test, seems to be randomly... if any bug related has been reported please let me know.. if I found the answer (still looking for) i'm gonna post here...

    Congrats for the great and polished engine... and thank you for saving me so much time of work...
     
  5. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    No, it should not become NULL during runtime. It is inited in the Start() call for the tilenode and should exist till the node objects is destroyed.

    If you are trying to access it during Awake() or Start() of another gameobject/component then you will get random results as the Start() of the TileNode might not yet have been called.
     
  6. Ycromix

    Ycromix

    Joined:
    Jan 1, 2013
    Posts:
    2
    Yeah I just found the problem, and it was exactly this, didn't realize the definition of an empty for the nodes was being called from Start(), thought it was being defined upwards... Thanks for the attention... lol
     
  7. flaye

    flaye

    Joined:
    May 24, 2012
    Posts:
    3
    Just got the plugin, and the possibilities to create a turn-based strategy game are great.
    One thing I noticed is the following code in a number of lines. Here's an example of one:

    Assets/Tile Based Map and Nav/Scripts/TMN/SelectionIndicator.cs(38,33): warning CS0618: `UnityEngine.GameObject.SetActiveRecursively(bool)' is obsolete: `gameObject.SetActiveRecursively() is obsolete. Use GameObject.SetActive(), which is now inherited by children.'


    Any info/updates regarding this? Thanks.
     
  8. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    That has been deprecated in Unity 4. You can simply replace it with SetActive(bool) if you want to.

     
  9. E1iTe

    E1iTe

    Joined:
    Aug 7, 2012
    Posts:
    47
    Ok I have FINALLY read through the whole thread and I have to say there was some pretty useful information in there I would like to think everyone that has participated in the thread as they have helped me a lot!

    Leslie: I noticed in an earlier thread that you have a script somewhere that basically can automatically unlike nodes that have a height difference of more then a value. I was wondering if that can be used at runtime. I have added a "jump" height variable to the units, and I was wondering if i can dynamically turn on and off links to nodes depending on height difference. ex. Unit A has a jump height of 2, Unit B has a jump height of 3.5. I want to be able to turn off and on the nodes heigher then 2 when Unit A is selected and heights higher then 3.5 when Unit B is selected. Also any way that i can check during movement if a Units next node is heigher then a value so I can turn on jump movement for moving to that next block then turn off jump movement for the rest of its moves until it reaches the destination?

    Thanks again!
     
  10. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    Check out MapNav.cs line 634, the SetupNodeLinkSwitches(float maxHeightDifference) fcuntion. That is what is called from the editor script when you use the tool that auto-unlink nodes that are too heigh from each other.

    Don't use it as is since that code is going through the whole map to change link status and can be slow. Besides, you only care to know about the height of the unit's neighbouring nodes if i understand your post correctly.

    Something like the following should do the trick ...
    Code (csharp):
    1.  
    2. public void UpdateNodeLinks(MapNav map, Unit unit, float maxHeightDifference)
    3. {
    4.     if (map.nodes == null || unit == null) return;
    5.     if (unit.node == null) return;
    6.  
    7.     maxHeightDifference = Mathf.Abs(maxHeightDifference);
    8.  
    9.     foreach (TileNode n in unit.node.nodeLinks)
    10.     {
    11.         if (n == null) continue;
    12.         float h = Mathf.Abs(unit.node.transform.position.y - n.transform.position.y);
    13.        
    14.         TNELinksOnOffSwitch ls = unit.node.gameObject.GetComponent<TNELinksOnOffSwitch>();
    15.        
    16.         if (h >= maxHeightDifference)
    17.         {
    18.             // height is greater than allowed, turn off the link
    19.             if (ls == null) ls = unit.node.gameObject.AddComponent<TNELinksOnOffSwitch>();
    20.             ls.SetLinkStateWith(n, false);
    21.         }
    22.         else
    23.         {
    24.             // Height was fine, so turn link back on if it is off. Only bother if a switch component is present
    25.             // as it won't be created if the link was not turned off. Default if for links to be active.
    26.             if (ls != null) ls.SetLinkStateWith(n, true);
    27.         }
    28.     }
    29. }
    30.  
     
  11. LordVe

    LordVe

    Joined:
    Dec 20, 2012
    Posts:
    4
    Leslie, I love this. It has taken so much of the work out of doing hex maps. For this I thank you. I do have a question though. If one were to want to create a 50x50 Hex Grid using Prefabs as the height generation, as you do in several of the samples, what would be the best way to place the prefabs. I wouldn't imagine placing 2500 prefabs into a map would be a very fun evening. And, since I have at least 10 maps of that size to attempt to create... Well, any help would be appreciated.
     
  12. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    Check a few posts back (and this one). I've linked the code to my game (that used hex maps). In there is editor scripts that generated my tiles.
     
  13. Elriks30

    Elriks30

    Joined:
    Jan 4, 2013
    Posts:
    1
    Hi,

    I create like bomberman and currently I have wished to know if your software allows you to "create randomly levels" by placing random places sprites (sprites and enemies if possible)

    Thanks
     
  14. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    Yes, random levels could be done. Everything you can do in the editor (related to the map&nav tools) can be done at runtime since the editor scripts are only making calls to classes/functions available in the normal/runtime scrupts..

    Placement of enemies does not have to be done in the editor and there are samples scenes that places units randomly at runtime.

    If you want to create maps at runtime (placement of tiles) you can still do that since all editor side tools of map&nav are making use of functions that are available at runtime too. So you can still have map&nav calculate over which nodes there are walls for example.
     
    Last edited: Jan 4, 2013
  15. JCouser

    JCouser

    Joined:
    Jan 5, 2013
    Posts:
    2
    Hi Leslie,

    I've recently purchased the map&nav system and it seems great! This will definitely save much time building the movement system.

    I'm currently developing a turn based combat game using many different character / movement types. I'd like for each character to have it's own particular movement script, which I'm assuming is modifications to the Unit script.

    We were working on a character whose movement would allow him to jump 2-3 spaces away, but not on any adjacent hex that surrounds him.

    Just curious if this is something doable, and where to begin.

    Thanks again for the assistance!
     
  16. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    It is certainly doable.

    A simple way of showing the valid 2-3 tiles away (which are the valid targets) would be to create a modifed version of the TileNode.cs ShowNeighbours() function. This function takes a radius to know up to how many nodes around the selected node must be shown. All you do then is exclude the direct neighbours from showing while still allowing the list to run throughy and find the further away neighbours. Direct neighbours are easy to find, they would be the nodes in the selected tile's nodeLinks array.

    If you want the Unit's movemenmt to also skip the 1st neighbour, on its way to the 2-3, then have a look at the NaviUnit.cs class to see how movement is handled by the samples. MoveTo() functions on lines 177 and 207. If you wnat it to still move normally to the target tile then the moveto fcuntions should be fine.
     
  17. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    I've submitted a small update to remove the warnings about deprecated functions under Unity 4 and permanently lowered the price to $25
     
  18. JCouser

    JCouser

    Joined:
    Jan 5, 2013
    Posts:
    2
    Thanks Leslie!

    With your direction I've finally modified both TileNode.cs and NaviUnit.cs to get my desired results. I just used the Hide() function against all of the nodeLinks tiles.

    Also, within NaviUnit I just perform a check to ensure the character type then set:

    followIdx = followPath.Length - 1

    He will then jump straight to the destination node. My only issue is when there is a wall node in front of the character, it's possible for the pathing system to reach the opposite side of the wall, allowing the unit to jump directly to the node passing through the wall. But I think with our level design we should be able to avoid this condition.

    Thanks again for the assistance.
     
  19. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    For the wall situation I would take the returned path and just count to see if there are "too many" nodes in it to reach the destination, then you know a path around the wall was calculated.
     
  20. Zygy

    Zygy

    Joined:
    Oct 29, 2012
    Posts:
    2
    Would it be possible to have a movement script that instead of limiting how far you could move instead made it so it took time to move there
    for example i want a person to walk all the way across a board but take a minute to do so.
    i was thinking the best way to do it would be to calculate the path and then time is 1 * followpath.Length seconds (1 tile per second)
    any ideas about where to start doing this and what functions i'll need to change in your scripts to make this work
     
  21. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    NaviUnit.moveSpeed :)

    Check out moveSpeed and moveSpeedMulti in NaviUnit.cs
    You can start by making moveSpeedMulti = 0.
    You could control the movement speed if you calculate a new "moveSpeed " and set it before calling the MoveTo() function or you cna have a look at the MoveTo() and _StartMoving() fucntions in NavUnit and create your own verison of these for better control.
     
  22. Sotto

    Sotto

    Joined:
    Apr 13, 2012
    Posts:
    4
    Nice work Leslie.

    Keep it up.
     
  23. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    853
    Finally having the time to play around with it a bit more... did any of the sample scenes include a version with a projector? I managed to align the movement indicators by tilting the nodes the same way as the terrain underneath them which works fine for a straight down bridge, but I can already see myself running into trouble with some more uneven terrain. Adding a projector to the UnitSelectionIndicator game object gave me some horrible results, but maybe I just set it up wrong...?
     
  24. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    I totally forgot about the projector. I read that it is not something you want to use though since it makes a scene very slow depending on how many you cast but I'll make a quick sample later today.
     
  25. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    853
    Thanks, looking forward to it. A projector for each reachable target tile might be overkill indeed, but a single one for the selected unit shouldn't be too much of a memory hog I guess.
     
  26. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    I've submitted an update with sample scene 7, showing how projectors could be used.
    The new tile node prefab for this is, \Assets\Tile Based Map and Nav\Prefabs\tile_nodes\TIleNode_Hex_projector

    $mapnav_projector.jpg
     
  27. Morgen

    Morgen

    Joined:
    Jan 2, 2013
    Posts:
    11
    Hello!

    There is feature that can make sometimes work with M&N lot easier. By default gizmo nodes are very small (0.2f, 0.1f, 0.2f)
    When tile size and tile spacing are 1 or so - it's ok, but when this numbers are 10 or even more (for some cases), they become too small, so you need to zoom in to select a node. Can you adjust gizmo nodes size depending on "scale"? Thanks
     
  28. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    Will be in update 2.8b.
    You can change the GizmoSizeDiv value (in TileNode.cs around line 542) if the size is still too small - a lower value will result in bigger gizmos.
     
  29. WitchKing

    WitchKing

    Joined:
    Jan 4, 2013
    Posts:
    13
    Hey there,

    This seems like a fantastic tool, perfect for what I'm working on! However, I seem to be having some issues with the install. I'm using Unity 4 and when I install it straight from the Asset Store I don't get the Map Nav option in the Window tab on the top menu bar.

    Furthermore, when I try to Play any of the sample scenes I get the "All compiler errors have to be fixed before you can enter playmode!" message. Running a debug on the MapNavCreateWindow script gives me the following errors on the RadiusMarker.cs script:

    48 public void ShowAll(bool adaptToTileHeight = false) - Default parameter specifiers are not permitted
    60 public void Show(Vector3 pos, int radius, bool adaptToTileHeight = false) - Default parameter specifiers are not permitted
    84 public void ShowOutline(Vector3 pos, int radius, bool adaptToTileHeight = false) - Default parameter specifiers are not permitted

    Re-downloading and re-installing gives me the same result. Is there something I'm missing lol?
     
  30. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    yes, the readme :)
    Check the dox, I explain how to extract the DLLs that where compiled for Unity 4. There are a few differences between Unity 3 and 4 so I have to include seperate DLLs made for Unity 4.
     
  31. WitchKing

    WitchKing

    Joined:
    Jan 4, 2013
    Posts:
    13
    Hmmm *scratches head* Yeah, I did do that, but maybe it's something else. After a bit more investigation this is what I'm getting:

    If I make a new project with just Map and Nav in, everything works fine and I can run the demos, use the tool etc. If I make a project with UniRPG (another awesome tool, by the way!) in and copy over the .dll's, everything's fine with that also. I seem to run into trouble when I import both packages into the same project - if I don't copy over the .dlls the Map Nav part works fine, but the UniRPG package doesn't, and if I do copy the 'dll's the UniRPG package works but the Map Nav no longer does.
    Is there something I'm missing that could be causing some incompatabilty?
     
  32. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    Sorry, I was mixed up anyway. This is about Map&Nav not UniRPG. UniRPG is the one that needs the seperate DLLs.

    Anyway, just did a test by importing map&nav and then unirpg and extracting the UniRPG DLLs since that is a must for Unity 4. The only problem I noticed was that the CameraMove.cs and CameraOrbit.cs scripts, present in both packages, are casuing problems. Just delete them from one of the packages but do note that the scenes for that pack might then have missing scripts on the "CamPivot" and "Main Camera" objects. You can fixs it though. CamPivot needs "CameraMove" on it and Mai nCamera needs "CameraOrbit" on it.

    The error you where getting about "Default parameter specifiers are not permitted" should not happen. I thought Unity supports that now cause it works for me and it the 1st time someone mentions that error here.
     
  33. WitchKing

    WitchKing

    Joined:
    Jan 4, 2013
    Posts:
    13
    Yeah was just having another look and had a feeling it might be to do with the camera being in both packages. Thanks, I'll give that a shot and let you know how I go - thanks for the fast reply too!
     
  34. WitchKing

    WitchKing

    Joined:
    Jan 4, 2013
    Posts:
    13
    Hey there,
    Yep, deleting the camera scripts from UniRPG fixed it ok. However I seem to be having another issue with Map and Nav now - yay for noobs!

    Following the tutorial vids, I set the Tile and Unit layers, and select New MapNav from the Map and Nav dropdown. In the popup box I get the option to set the Tiles layer, but there's no option to set the Unit layer. I then fill in the Width x Length. Then when I hit Create MapNav, it makes the MapNav object, but with no Nodes on it.

    Reading through the thread I saw someone else had the same error, but didn't quite understand how they solved it, sorry - something about setting some prefabs or something that I didn't get. If I set the TileNode Prefab to one of the prefab objects and hit Create MapNav, I get a MapNav object with just one node. Is there some step somewhere I'm missing?
     
  35. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    Units layer has been removed in the latest versions since it was not needed and not part of the core system.

    Your most likely problem is that you have not specified a TileNode Prefab, or whatever you assigned in that fields was not actually a TileNode prefab. Such a prefab must have a TileNode compnent on it and you can find the sample prefabs in /Prefabs/tile_nodes/

    Also check if you are getting any errors (red messages in Unity console). When errors comes up they normally prevent the script from executing properly and can cause all kinds of problems. Best is to copy-paste the message here so I can see on what line number the error happens and can in that way figure out exactly what is wrong on your side.
     
  36. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    853
    Hey Leslie,

    I tried to rewrite/copy one of the functions in TileNode.cs to return a list of nodes with units on them so I could highlight all the affected tiles rather than all in range. However, I still get a list of far more nodes than I should.

    Code (csharp):
    1.  
    2.     public List<TileNode> GetAllUnitsInRange(int radius, int playerSide)
    3.     {
    4.         List<TileNode> ret = new List<TileNode>();
    5.         List<TileNode> helper = new List<TileNode>();
    6.         _GetAllUnitsInRangeRecursive(radius, playerSide, ref helper, ref ret);
    7.         return ret;
    8.     }
    9.  
    10.     private void _GetAllUnitsInRangeRecursive(int radius, int playerSide, ref List<TileNode> helper, ref List<TileNode> retNodes)
    11.     {
    12.         this._ShowNeighboursRecursive_Helper = radius;
    13.         helper.Add(this);
    14.  
    15.         radius--; if (radius < 0) return;
    16.         int r = radius;
    17.  
    18.         foreach (TileNode node in this.nodeLinks)
    19.         {
    20.             if (node == null) continue;
    21.             if (helper.Contains(node))
    22.             {
    23.                 if (node._ShowNeighboursRecursive_Helper >= radius) continue;
    24.             }
    25.  
    26.             r = radius;
    27.  
    28.             if (node.units.Count > 0) continue;
    29.            
    30.             Debug.Log ("There is a unit on node " + node.transform.name);
    31.  
    32.             // this node seems fine, incl in return list
    33.             retNodes.Add(this);
    34.  
    35.             // on to the next
    36.             if (r > 0)
    37.             {
    38.                 node._GetAllUnitsInRangeRecursive(r, playerSide, ref helper, ref retNodes);
    39.             }
    40.         }
    41.     }
    42.  
    I thought checking node.units.Count > 0 would only give me nodes with at least one unit on it, but apparently I am missing something here. I haven't included the intended check for playerSide yet because I wanted to get the finding function right first.

    [edit] Changing this line gives me different results, but they are still wrong.

    Code (csharp):
    1.  
    2. if (node.units.Count > 0) retNodes.Add(this);
    3.  
     
    Last edited: Jan 15, 2013
  37. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    Try this. It should return nodes with only units on them. You can modify the if statement for "retNodes.Add(this);" to include only the wanted side's units.

    Code (csharp):
    1.  
    2. public List<TileNode> GetAllInRangeWithUnits(int radius)
    3. {
    4.     List<TileNode> ret = new List<TileNode>();
    5.     List<TileNode> helper = new List<TileNode>();
    6.     _GetAllInRangeWithUnitsRecursive(radius, ref helper, ref ret);
    7.     return ret;
    8. }
    9.  
    10. private void _GetAllInRangeWithUnitsRecursive(int radius, ref List<TileNode> helper, ref List<TileNode> retNodes)
    11. {
    12.     // check if a unit on the node
    13.     if (this.units.Count > 0  !retNodes.Contains(this))
    14.     {
    15.         retNodes.Add(this);
    16.     }
    17.  
    18.     this._ShowNeighboursRecursive_Helper = radius;
    19.     helper.Add(this);
    20.  
    21.     radius--; if (radius < 0) return;
    22.  
    23.     foreach (TileNode node in this.nodeLinks)
    24.     {
    25.         if (node == null) continue;
    26.         if (helper.Contains(node))
    27.         {
    28.             if (node._ShowNeighboursRecursive_Helper >= radius) continue;
    29.         }
    30.  
    31.         // test the next node(s)
    32.         if (radius > 0)
    33.         {
    34.             node._GetAllInRangeWithUnitsRecursive(radius, ref helper, ref retNodes);
    35.         }
    36.     }
    37. }
    38.  
     
    Last edited: Jan 15, 2013
  38. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    853
    Yes, that looks much better. However, I had to pass the attack range variable with a +1 modifier since a unit with an attack range of 2 apparently only tested for one adjacent tile rather than two. Including its own node in the list first seemed like an error to me, but it makes sense of course - after all, some "attacks" might even target the current unit itself (think medpacks for example).

    As far as I can tell, your version does not care for wall tiles or tile type masks, right? That's the behavior I intended, just asking since think I had one occasion where it didn't work, though that might have been a result of the above problem.
     
  39. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    I've not tested this code so there could be problems.

    Yes, there is no checking walls and such and the node that the unit is standing on is included. I figured once you add something that test the "side" then the original node would be excluded. The reason for the +1 could be caused by a combination of the if() on line 31 and the .Add being done on line 14.

    You could try a modification like this (basically moving the .Add into the loop). This will exclude the first (origin node) and should get rid of the +1 bug.

    Code (csharp):
    1.  
    2.     private void _GetAllInRangeWithUnitsRecursive(int radius, ref List<TileNode> helper, ref List<TileNode> retNodes)
    3.     {
    4.         this._ShowNeighboursRecursive_Helper = radius;
    5.         helper.Add(this);
    6.  
    7.         radius--; if (radius < 0) return;
    8.  
    9.         foreach (TileNode node in this.nodeLinks)
    10.         {
    11.             if (node == null) continue;
    12.             if (helper.Contains(node))
    13.             {
    14.                 if (node._ShowNeighboursRecursive_Helper >= radius) continue;
    15.             }
    16.  
    17.             // check if a unit on the node
    18.             if (node.units.Count > 0  !retNodes.Contains(node))
    19.             {
    20.                 retNodes.Add(node);
    21.             }
    22.  
    23.             // test the next node(s)
    24.             if (radius > 0)
    25.             {
    26.                 node._GetAllInRangeWithUnitsRecursive(radius, ref helper, ref retNodes);
    27.             }
    28.         }
    29.     }
    30.  
    For checking walls and perhaps other things you could do two things.

    In Battlemass I use a raycast to check if there is a wall in the way., so all my walls had colliders and was set to a certain layer (check a few posts back, I've given a link to the sorce code of BM).

    The other way and something I would try first if I where to do BM over is to calculate a path to the node that a potential target unit is sitting on, using MapNav.GetPath and passing validNodesLayer=0. This should return a straight path to the target, ignoring obstacles. You then run through the nodes of this path and check if certain obstacles, like a wall, is present.
     
  40. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    853
    Yes, that solved it. I shall experiment with this some more - maybe adding teams to make more use of the playerSide idea.

    I think I like the raycast idea more as it's closer to our usual boardgame rule, "If you can draw a line from the center of your unit to the center of his, you can attack it". :) Though I guess one could argue that you don't need to see the enemies body to shoot his arm.

    Now if there was an arc-cast for throwing grenades...
     
    Last edited: Jan 16, 2013
  41. E1iTe

    E1iTe

    Joined:
    Aug 7, 2012
    Posts:
    47
    Has anyone finished any more sample playmaker scripts for Map&Nav? I've been trying to create my own and so far I completed the spawn unit and one two show the movements that are allowed but i am having trouble finding a way when i can click on a tile. Any help would be appreciated!

    Thanks Guys
     
  42. murteas

    murteas

    Joined:
    Feb 14, 2012
    Posts:
    62
    I didn't realize there were any at all. That would be great to have some playmaker scripts for this. Can anyone point me to the ones that exist now?
     
  43. E1iTe

    E1iTe

    Joined:
    Aug 7, 2012
    Posts:
    47
  44. blockimperium

    blockimperium

    Joined:
    Jan 21, 2008
    Posts:
    452
    How can you handle:

    1) units with more than one weapon
    2) units that 'visually' take up more than one tile (large ship as opposed to fighters)
    3) units that change their orientation (I just landed so now I'm a land unit and should follow those rules)
    4) minimum fire range (artillery must fire a minimum of 2 tiles away)
    5) extending the map tile properties (similar to what you did with movement cost)
     
  45. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    853
    While that might not be a perfect solution (and isn't exactly a TBM&N issue to begin with) I have set up some additional GameObjects in the unit.cs script to represent a primary and secondary weapon instead of simply using the SampleWeapon.cs component. A better approach might be to use a SampleWeapon[] array and loop through all equipped weapons.

    I have added this snippet to the CanAttack() function in unit.cs, right before the // finally check if target is in range section. A quick test looks promising.

    Code (csharp):
    1.  
    2.         int minRange = 2;
    3.    
    4.         ...
    5.        
    6.         if (this.node.TileCountTo (target.node) < minRange)
    7.         {
    8.             Debug.Log ("Target is too close!");
    9.             return false;
    10.         }
    11.         ...
    12.  
    As far as I understood the comments, TileCountTo ignores additional tile costs and layers and just gives the pure distance based on the NavMap and all available links. minRange would be taken from the Weapon script rather than being hard-wired into this function of course.
     
    Last edited: Jan 21, 2013
  46. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    1) like @c-Row said. Not really MapNav related. The samples I gave is just that, samples. They are there to show you a possible way of using the grid system presented by MapNav. How you implement this will depend on your game design cause you will have rles like, al lweapons fire at same time, or a player ma ychoose to only use the one ot the otehr weapon per turn, etc etc.

    2) This package was coded to support units that takle up one tile space only and I have no plans to introduce support for bigger units. I think this subject has bene touched on before, check some of the olde rposts, but I do not think a real solution was posted. A lot of the core of the system would have to be rewritten to support bigger units as checks would have to be done to see if they can move to certain tiles, etc.

    3) That should be as easy as changing NaviUnit.tileLevel = TileNode.TileType.Normal; (default for land). Note that you can add and change these TileTypes by editing the TileNode.TileType enum. As you might have noted, the sample Units class inherits from the NaviUnit.

    4) What c-Row said. Also check some older posts, I think there was discusison on marking such tiles.

    5) Not quite sure what you mean by this.
     
  47. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    853
    Hey Leslie

    Is there a reason why the units pause for a little moment after reaching a tile? I understand that there is a possible small delay when simultaneous movement is active, but when moving only one unit at a time I couldn't find where this delay comes from.
     
  48. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    I think "Same time movement" is on by default for the sample's units and with this the Units are moving from tile to tile, linking with tiles as it goes and calculating a new tween to get to the next tile. This is needed so that the units are linked with the correct tile at all times, but not needed if units are nto all gonna move at the same time, in which case, disable the option "usingSameTimeMovement" in the unit's inspector.
     
  49. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    853
    Ah, didn't realize the units would stick to this behavior even though the Game Controller was set to not use simultaneous moves. Turning off makes them move smoothly. :)
     
    Last edited: Jan 23, 2013
  50. Holt

    Holt

    Joined:
    Jan 29, 2013
    Posts:
    1
    Hello,

    I briefly went through the thread and didn't see anyone ask this. But are we able to add our own custom models instead of using the ones that you provide?

    So if I wanted to create human objects (cavalry/archers/foot soldiers/etc) instead of tanks/planes/boats/etc.

    Thanks,
    Holt