Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

TurnBased-Toolkit (TBTK)

Discussion in 'Assets and Asset Store' started by Song_Tan, Aug 11, 2013.

  1. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,960
    Noted. I'll look into it and make some tweaks.
     
  2. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Thanks Songtan.

    Quick question. I've developed some modifications to my untiTB to allow it be asleep (stunned) and awaken when an enemy approaches to an adjacent cell or if its attacked. This seems to work fine except that the unit is still visible when it's asleep with a red hostile marker. Is there anyway I can turn off the red hostile indicator on a unit and then turn it back on during the game? I'm using this for hidden enemy that look like rocks and then ambush / attack the player character when they approach too close.

    Also, when I spawn a new enemy unit during gameplay using the functions you mentioned earlier, the enemy isn't visible until one of my units completes a move. They remain invisible even if directly infront of one of my units and then appear only after my unit has moved. Is there a function to call to refresh the list of visible units? I presume it must get called at the end of a unit's move so perhaps that would be a good place to look.
     
  3. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,960
    You can check for PlaceIndicatorH() in GridManager.cs. That is where the indicator is position onto each tile. You can do a condition check before placing the tile so that unit that are asleep is not high-lighted.

    You need to check for the unit visibility right after you spawn it. To do that, simply call AIUnitCheckFogOfWar() on that unit instance. The code should take care of the rest.
     
  4. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,960
    Guys, just a head up to what comes next. If you follow my development blog you might be aware that I'm working on adding vertical component to the existing grid system. Here's a sneak peak of it.


    As you can see from the image it's compatible with existing features (walls and obstacle, fog-of-war, cover system). As far as the game mechanic concern, traversing from tiles of different height cost extra movement range, and attack from higher/lower ground does gives a bonus/penalty. That's about it. I'm planning to test it out for a bit before releasing the next update. But anyone who is interested in check it out or help me test it, perhaps tweak/add a thing or two can give me a shout. I'll be quite happy to send you an advance copy.
     
  5. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Looks fantastic. How will you handle the animation of a unit moving to a higher or lower tile. Will they rise vertically or move at an angle up towards the next tile.
     
  6. moure

    moure

    Joined:
    Aug 18, 2013
    Posts:
    184
    Thats a much requested addition songtan, i would be happy to test it out and give you some feedback, cheers ;)
     
  7. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,960
    @Rajmahal, right now, I'm not bother about handling animation. My guess is depends on each individual game and the asset being used, the animation solution required will be different so most likely I'll just leave it to the user. So yes, for now they just move at an angle towards the next tile.

    @moure, please send me an email so I can send you the relavent scripts.
     
  8. vonpixel

    vonpixel

    Joined:
    Oct 2, 2012
    Posts:
    31
    sweet! Im stoked!
     
  9. ChunkoGames

    ChunkoGames

    Joined:
    Jul 15, 2013
    Posts:
    20
    Hi,
    which game object/script stores a complete list of the players units? I'm trying to add a UI feature which will show the player a count of how many units he can currently move/attack with.

    Also I love the toolkit!
     
  10. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,960
    You can get a list of the units of a particular faction using UnitControl.GetAllUnitsOfFaction(int factionID). You will need to pass the factionID of the player faction (as specified in GameControl).
     
  11. ChunkoGames

    ChunkoGames

    Joined:
    Jul 15, 2013
    Posts:
    20
    Thanks!
     
  12. ChunkoGames

    ChunkoGames

    Joined:
    Jul 15, 2013
    Posts:
    20
    Also, how would I check if a specific unit has a target in range which it can hit (I need to check for attacks left and enemies in range).

    EDIT: nvm I worked it out myself. Thanks anyway.
     
    Last edited: Mar 13, 2014
  13. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,960
    you can check for attack remaining for tha unit by reading the variable 'attackRemain' on the UnitTB instance. There's no way to know how many hostile unit is in range. You will have to use a custom function like this to find out:

    Code (csharp):
    1.  
    2.     public static int GetHostileUnitInRange(Tile srcTile){
    3.         UnitTB unit=srcTile.unit;
    4.         int hostileCount=0;
    5.         List<Tile> tempList=GridManager.GetTilesWithinRange(srcTile, unit.GetAttackRangeMin(), unit.GetAttackRangeMax());
    6.         foreach(Tile tile in tempList){
    7.             //if the tile is occupied by a unit and it's from other faction
    8.             if(tile.unit!=null  tile.unit.factionID!=unit.factionID){
    9.                 bool LOSFlag=true;
    10.                 if(GameControlTB.EnableFogOfWar()){
    11.                     int dist=GridManager.Distance(tile, srcTile);
    12.                     LOSFlag=IsInLOS(srcTile, tile)  dist<unit.GetUnitSight()  tile.unit.IsVisibleToPlayer();
    13.                 }
    14.                
    15.                 if(LOSFlag){
    16.                     hostileCount+=1;
    17.                 }
    18.             }
    19.         }
    20.         return hostileCount;
    21.     }
    22.  
     
  14. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    How can I break the connection between two tiles so a unit can't go from one tile to another right next to it? Sort of like the way walls are handled but so they don't block view. I've been looking at the way walls are handled hoping I can figure out something, but I haven't been able to discern how the stop movement between tiles.
    Thanks!

    edit: Never mind. Figured it out. I set up a simple loop in the start of "Tile.cs" to check all neighbors and if itself and a neighbor both have a certain tag, it removes it from the neighbors list. Was looking at the wrong thing! Should have been looking for neighbors not walls. Still need refining as that will not allow a long stretch of broken tiles but it's a start! maybe a two tag system is the way to go.

    edit 2: So here's how I did it: set up four Boolean, one for each side and then run a check at awake to check if two tiles have opposite sides "disconnected". So if a tile has disconnectTop==true and a neighbor has disconnectBottom==true, it will disconnect the two tiles. Probably not the best way but it works and only runs once so it's no biggie deal if it's not the best way. Sure, there will be some set up that needs to be done and it won't work for tile maps generated at runtime, but for my needs, it's suitable.
     
    Last edited: Mar 13, 2014
  15. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,960
    Sorry for the slow respond. I went out for a bit.

    You can still use wall. There's no requirement that a wall needs to have a wall prefab or mesh object. In fact in the GridPainter, you can select "no visible wall" as the wall prefab option. That would block any connection between 2 tiles just like you need, without any wall object to block the view.
     
  16. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    Thanks! I was sure I tried that, but I guess not.
     
  17. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Actually, I think this only applies when the ability targets a tile rather than a friendly / hostile unit. That actually makes sense so I don't think this is a bug. Sorry if you wasted any time looking into it.
     
  18. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    I'm looking at some ways to optimize my game and I have a question regarding using LOD's with this toolkit. I'm somewhat new to LOD's so this may be a very silly question but my understanding is that I would create an LOD group object for each unit and attach the various LOD meshes into the object. This would then be parented with the unit gameobject that has the UnitTB script on it. However, can the animations still work with LOD's since I have to specify the animation body that has the animations in the editor. But if I have the animations in different LOD meshes ... will that no longer work? Would I have to go into the code and change the animation body depending on which LOD is being used or is there a much easier way (or will Unity handle it automatically)?

    Apologies again if the above is just a silly question ... I'm completely new to LOD's in Unity as I only just got Unity Pro.
     
  19. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,960
    Dont worry about the ability shootObject. I've looked into the code, while the shoot to tile when targeting tile is working as intended in the first place. I spotted a few other minor issue that I've since fixed.

    About LOD, I'm sorry to say I dont know the answer myself. See I dont even have Unity Pro (surprise!). But I guess you can try it out yourself to find out. No harm trying. Just duplicate a backup project before you do that. My guess is if you are using still using legacy animation, as long as the bone hierarchy of the meshes with different LOD is similar, it should work.
     
  20. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Cool ... I'll play around with it and let you know. I mainly need LOD's for mobile development but there, I think I can always just deactivate the action cam and stick to using the new LOD models all the time.
     
  21. ChunkoGames

    ChunkoGames

    Joined:
    Jul 15, 2013
    Posts:
    20
    Hello, I've recently encountered two issues.

    While testing a customized level, I noted that on several occasions when the creeptank2 fired, the bullet fired into the air then flew upward and hung there for several seconds before crashing to the ground. This seemed to happen more often when around a hexhalf obstacle.

    Secondly, on larger maps I've found that the enemies will not engage until I move a unit within range of them. Please note that fog of war is disabled. Is there a way to make the enemies always pursue you.
     
  22. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    Please stop quoting the entire first post.
     
  23. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,960
    Please try not to quote the entire first post. It would make this thread easier to read.

    Now to the issues. The first one is indeed a bug. I've been revising the code of the shootObject to get rid of issue such as the one you are facing. Hopefully by next update the new code should be free of bugs like this.

    For the next one, sounds like you have set your AI to Passive mode. Fyi, you can set the AI behaviour in AIManager, just look for "TBTK/GameControl" in the Hierarchy. There are 3 modes which are Passive, Trigger and Active. Their coresponding behaviour is explained in the tooltip when hoevered over. Basically passive means the AI wont do anything until hostile unit comes within range, Trigger means the AI will remain dormant until a hostile spotted or attack it, Active means the AI will active move around seeking for target. Just change it to Active and it will be what you are looking for.
     
  24. DonSonz

    DonSonz

    Joined:
    Aug 19, 2013
    Posts:
    16
    Hi Songtan

    Will TBTK support Unity 5 when it will be released?
     
  25. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,960
    It's really hard to say at this point. We dont know if there's any old feature will be obsolete in Unity5. And without the actual Editor to test on, there's no telling if there's any under-lying issue running current TBTK in Unity5. But having say all that, Unity5 will most probably be supported. No reason not to move forward and stay up to date. We'll see. My guess is it's still long way from actual release so there's no need to worry about it. At least in the near future.

    The good news is the new GUI will be available in 4.6, which will be release in 'spring' according to Unity. I'm very much looking forward to see if I can work something out with that.
     
    Last edited: Mar 18, 2014
  26. ChunkoGames

    ChunkoGames

    Joined:
    Jul 15, 2013
    Posts:
    20
    Thanks, that worked!
     
  27. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,960
    Hi guys,

    A new update has just gone live on AssetStore. With it comes the new vertical component for th grid, as well as the a better optimized grid generation algorithm to increase the generation time and grid size limit.

    Please keep in mind that I've done some rather drastic change to how certain things work in this new version so there might be some unexpected bug. If you have encounter any, I apologize in advance, but please do let me know what are they so I can get it fixed.

    Hope you enjoy the update!
     
  28. kelus

    kelus

    Joined:
    Mar 26, 2014
    Posts:
    2
    Hello. First I wanna thank you for this great asset!
    I'm working on some project and I have problem to change code (i'm not a good coder at all :p). I want to change attack, defense and damage. What I want is to when unit attack it rolls a random number from 1-6 and defeding unit do the same roll. Attacker hits when his generated number is higher than defender generated number ;) Damage is the difference between attack and defense. Please can you help me with that? :)
    Cheers.
     
    Last edited: Mar 26, 2014
  29. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,960
    That should be relatively easy. I'll get to it when I have time. Can you email me so I can send you the modified script when it's done?
     
  30. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    I can get you started but it might be a rather involved process. Are you sure you want to attempt it? If you're not comfortable with code, you might make things worse. Anyway, here's how I would do the check. It uses the existing code as much as possible but doesn't take anything into account but the simple roll when figuring the attack (no cover, perk bonuses, etc.) .
    Look for "//calculate if the attack hits" in UnitRB.cs.
    Then add/edit:
    Code (csharp):
    1.  
    2. int attackerRoll = Random.Range(1,7);//goes to 7 but will never roll a 7
    3. int defenderRoll = Random.Range(1,7);
    4. int difference = attackerRoll-defenderRoll;
    5. float hitChance=Mathf.Clamp(difference, 0, 1f);//edit the line that is already there with the variable call
    This way, the hit chance will always be either 0 (miss) or 1 (hit) and will work with the rest of the attack code with no additional modification. Doesn't handle the damage but you do have the difference already set up. If I have time, I look for this later. Maybe Song will come on and tell you a totally different way. If so, use his.

    edit: heh. Beaten by him.
     
    Last edited: Mar 26, 2014
  31. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,960
    @drewradley, Thanks a lot for the detail explaination.

    It's relatively easy yes. In fact you can tell there's only 4-5 line of codes required. However if you dont understand where to insert these lines and replace the existing one, It could still be very tricky. Of course I could give a detail step by step guide, but I figure it would be quicker to just do it myself and send over the modified scripts.
     
  32. JeromeF

    JeromeF

    Joined:
    Feb 1, 2014
    Posts:
    5
    Hi songtan !
    Can you send an email to those who bought the game outside the asset store ?

    Thank you
     
  33. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,960
    Very very sorry. I've totally forget about that after waiting for a very long upload time. I've just done it tho, please check your email.
     
  34. JeromeF

    JeromeF

    Joined:
    Feb 1, 2014
    Posts:
    5
    Better late than never,
    thank you for this email :)
     
  35. kelus

    kelus

    Joined:
    Mar 26, 2014
    Posts:
    2
    @drewradley
    thank you for help! :)
    @songtan
    I emailed you as you asked.
     
  36. ChunkoGames

    ChunkoGames

    Joined:
    Jul 15, 2013
    Posts:
    20
    Right now I'm trying to have each units health and AP displayed in a GUI box nearby the unit when it is selected. How would I go about doing this? More specifically how do I get the position of a unit on the screen.

    EDIT: Also to be more specific I want to have these displayed as numbers instead of bars.
     
    Last edited: Mar 27, 2014
  37. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    Are you using the NGUI version? If so, I can help you but it's going to take some code editing if you are up for it.
     
  38. ChunkoGames

    ChunkoGames

    Joined:
    Jul 15, 2013
    Posts:
    20
    I'm not using NGUI. I've already been doing a lot of coding for this project.
     
  39. ChunkoGames

    ChunkoGames

    Joined:
    Jul 15, 2013
    Posts:
    20
    Do you know of any effective methods for visually indicating that a unit cannot do anything else this turn. I tried lowering the saturation of units who had already moved, but that did not work as there is not tenderer.
     
  40. E1iTe

    E1iTe

    Joined:
    Aug 7, 2012
    Posts:
    47
    Hi @Songtan glad to see there is still work being done on this toolkit! I love the implementation of the height system. The only change I would love to have is that each unit has a different max height difference in levels... ie. Unit 1 can "jump" up three units where Unit 2 can only "jump" one unit up. Would this be difficult to modify? Also would you have any time to make a quick video on how to add one more variable for a unit. ie. if I wanted to add another variable for a unit like HP or AP so I can use that as a basis to add more?
     
  41. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,960
    Sorry for delay guys. For some reason I havent been receiving any notification about any new post for the past few days..

    You can get the screen position of a unit by using WorldToScreenPoint. You can refer to UIOverlay.cs. That script basically responsible for getting unit position and draw various overlay element on screen (HPBar, APBar, damage) so there's plenty of example (particularlly at line 242). You can pretty much recycle the code. Just make sure you use the unit position for the WorldToScreenPoint function.

    It really depends on your game and the UI design really. There's a lot of way this can be done, maybe an icon or an overlay indicator on the unit, in game indicator (like those default select or hostile indicator), or fade the unit out like you try. Any of them can be a effective methods when done right.

    For your method, I assume you are trying to change the properties of the material on the renderer? There has to be renderer components on the unit, otherwise the unit model wont be showing. But assuming you are using the same hierarchy as the example unit, the renderer is not on the unit rootObject but on the various child object (note a unit can be made of many mesh, each need a renderer). So you have to loop through each and every one of them to change the saturation.


    I suppose it's not too difficult to limit the unit "climb" distance. I'll look it up when I have time. But please keep in mind this might not be happen anytime soon.

    Adding variable on the other hand, I'm afraid that is not something I can show on a video. It's everything to do with coding. If you know how to code, you can easily look into the script and figure it out. If not, I might as well teach you how to code. The thing is showing and step to step of that is pretty pointless in my opinion if I'm honest. Either you already know I'm talking about, or you will still be none the wiser after going through all the steps and cant do anything useful beyond what is already shown.
     
  42. ChunkoGames

    ChunkoGames

    Joined:
    Jul 15, 2013
    Posts:
    20
    Thanks for the help!
     
  43. Bud-Leiser

    Bud-Leiser

    Joined:
    Aug 21, 2013
    Posts:
    93
    Song are you updating the tutorial/documentation as you move forward? Can you post it on your main site so I can link to it?
     
  44. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,960
    I assume the tutorial you are refering to are the video tutorials? If that's the case, no I dont really update it. I dont know anything about editing video. Redoing the whole video after every update is kind of pointless considering most of the work flow is still the same. However I do update the pdf documentation. But that is only half of the content really. All the editors of TBTK contains tooltip. Only half of those tooltip are in the pdf documentation and that's pretty much all about the pdf documentation. So if you'll be better off just looking at the tooltip, if you know the basic work flow (which you should be able to know from the videos).
     
  45. Azzerhoden

    Azzerhoden

    Joined:
    May 21, 2013
    Posts:
    5
    Just started playing around with the TBTK as part of a custom UI. When I run my scene I see a 'Pause - Menu' button in the upper right corner. How do I turn this off? I cannot seem to find an option for this.

    Do I have to go in and edit the code to remove this?
     
    Last edited: Apr 9, 2014
  46. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,960
    If you are refering to NGUI, you dont need to. You can simply move the button off the screen. The button object is in TBTK/UI_NGUI/Camera/Panel/ScHUD/AnchorTopRight/ButtonOption

    If you are refering to the default UI, I'm afraid you have to edit the code a bit. It's very simple, just comment out line156 to line158 of UI.cs and that's it.
     
  47. Azzerhoden

    Azzerhoden

    Joined:
    May 21, 2013
    Posts:
    5
    It was the default UI - commenting out the code did the trick. Thanks!
     
  48. Reliique

    Reliique

    Joined:
    Apr 11, 2014
    Posts:
    4
    Hello mate, great package thank you a lot for making it!

    I have couple of questions:

    1. How to make terrain behind the hexgrid? Should it be either Unity terrain as background (3D) or basic plane with texture attached to it (2D)?
    2. Haven't been able to figure out how to add lightning, I add directional lightning and it just dosen't light up the scene at all.
    3. I'm making a hexagonal chess based game, so I need fixed positions for all units at the start of the game (rook, knight, queen, king etc) is that possible?
    4. I also need to make custom movement for Knight, is it possible for Knight to make "Г" shaped move and return back to starting position after attack?

    Thank you Songtan! Kudos for making this toolkit!
     
  49. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,960
    Thanks!

    1. You can add whatever visible object to the scene to add as background. 2D or 3D, Unity terrain or custom mesh, it doesnt matter. As long as you make sure they are collider free they shouldnt be interfering with the core framework. And obviously, position them so they show up in the camera.

    2. This shouldnt have anything to do with the TBTK. Please note that the grid doesnt react to light, you will have to adjust the color of the material. Only the units react to the lighting.

    3. You can hand place the position of each unit using GridManager. Just disable 'RandomizeGridOnStart' and 'RandomizeUnitOnStart' flag on GridManager.

    4. Now I'm not sure what exactly you want to implment a chess. The toolkit doesnt work this way (the attack unit doesnt move into the tile which it attacked) so I'm struggling to understand the big picture. Also you are using hex-grid, so how's tradditional chess piece movement translate to that? In current build, a unit cannot do a specific move pattern. They are allow to move into any tile in range as long as there's a path. With some extra coding, yes it can be done. But it wont be a few lines of code.
     
  50. Reliique

    Reliique

    Joined:
    Apr 11, 2014
    Posts:
    4

    Thx for above answers and bloody fast response!

    Chess is actually quite simple, the rules of hexagonal chess apply but with some custom modifications, this picture will make it a more clear to you and you will also understand why I choose TBTK:



    I will be using Hextech 3.0 asset for global map and TBTK for battles.

    By the way would you be interested in making a custom job? As paid work of course and its obviously related to hexagonal chess and TBTK.

    Have a nice weekend!
     
    Last edited: Apr 11, 2014