Search Unity

  1. How can our website serve you better? Give us your feedback. Take our survey and let us know.
    Dismiss Notice

TurnBased-Toolkit (TBTK)

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

  1. al_dude

    al_dude

    Joined:
    Jan 6, 2017
    Posts:
    14
    Hello, how would I go about making custom obstacles?
     
  2. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    There's a section in the documentation 'Obstacle and Wall Prefab'. That should tell you what you need to make a prefab. Once you have done that, you can assign it to the GridGenerator in using Inspector (just expand 'show default editor' and you will see where all the prefab that used to form the grid are assigned).
     
  3. al_dude

    al_dude

    Joined:
    Jan 6, 2017
    Posts:
    14
    Thanks. Is it possible to have some sort of victory condition?

    From what I can see, defeating enemies or being defeated result in the same outcome, showing game over message with three buttons.
     
    Last edited: Sep 20, 2019
  4. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    The only victory condition is to destroy all hostile unit. The system does determine if a player faction wins the game or not. However it's not stated in the game-over screen. I can make a small modification so that it shows something like 'You Have Won' instead of 'Game Over' when a player won the game. Send me an email and I'll pass you the modified script.
     
  5. al_dude

    al_dude

    Joined:
    Jan 6, 2017
    Posts:
    14
    That would be mighty great.
     
  6. al_dude

    al_dude

    Joined:
    Jan 6, 2017
    Posts:
    14
    Thanks, got it working.
     
  7. freezepro

    freezepro

    Joined:
    Aug 30, 2019
    Posts:
    2
    Hello, we have a need to render 20 000 - 40 000 hexagons(each represents a player/unit).
    Could you please tell if you engine will handle those? how those hex are made, are these 3D models?
     
  8. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    As far as rendering are concern, everything is Unity's default. So TBTK is not really a limiting factor in this.

    The hex/square grid are made of individual model but they are combined into one single mesh during runtime (unless you want to use grid with varying height). I've tried with grid with a dimension up to 150x150 (approx. 20 000 hex) without any problem. That said, a lot of this depend on the machine you are running this on and what else of optimization you have in place.
     
  9. SweetBro

    SweetBro

    Joined:
    Jan 14, 2013
    Posts:
    64
    How extensible is this from a programmatic standpoint? I have a few weird mechanics I want to test out, but this seems to cover a lot of the existing boilerplate I would need to write. On a related note, I can't seem to find a Scripting Reference Doc, is one not available online?
     
  10. BlankMauser

    BlankMauser

    Joined:
    Dec 10, 2013
    Posts:
    116
    Are there any serializing features such as undo/redo turns and save/load states?
     
  11. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    There's no scripting reference I'm afraid. And I'm not sure how to answer the question how extensible the framework is without any context. Perhaps you can give me some idea of what are the things you are trying to do.

    Unfortunately no. There are no undo or saving system of any description.
     
  12. Tarrasque

    Tarrasque

    Joined:
    Jan 5, 2015
    Posts:
    21
    I´m planning to have different combat backgrounds based on the enemy creature. So for example if enemy is Giant Scorpion the combat takes place in desert, undead creatues in graveyard etc. How would you recommend doing this? Should there be different scenes or would it be better to use one scene and just load a different set of obstacles and ground texture?
     
  13. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    It's entirely up to you. As far as I can tell the upside of putting everything in one scene and switch thing on/off, or load/unload things is minimized load time. On the other hand, separate all the environment object and hostile units into different scene is much more manageable. Personally, unless the levels are relatively short and need loading/switching frequently, I would go with the latter.
     
  14. Sevenar

    Sevenar

    Joined:
    Mar 7, 2015
    Posts:
    2
    Is it possible to have units with multiple weapons, like a battleship with three 3-gun turrets? If so, can they have limited firing arcs? How about individual systems to damage, like Engine hits reduce movement allowance, Sensor hits reduce weapon/fog of war range, etc.?
     
  15. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    Yes and no. By default, a unit only have one default attack (weapon if you like). But you can use the ability system to give the unit alternate attacks with different properties. I'm not sure what do you mean by limited firing arcs? The unit can only fire towards certain direction? I should point out that the framework doesn't take unit facing into gameplay consideration. While it's relatively easy to add a directional restriction to the attack, the problem is you will then need to allow the player to control the unit facing direction and having the UI present that information.

    This is not supported by default I'm afraid. But if you are familiar with coding, it's not tricky to modify the framework to support it.
     
  16. Sevenar

    Sevenar

    Joined:
    Mar 7, 2015
    Posts:
    2
    Yes, as in the front turret on a battleship cannot rotate to fire directly behind the ship, and the aft turret cannot rotate to fire directly ahead. But if the engine doesn't track unit/target facing, I suppose that's going to be difficult to implement.

    I suppose it would require the ability to reduce individual stats instead of just all damage being applied to a unit's HP. But then you'd need to track damage allocation by unit type as well, because, say, an infantry squad that has taken 50% damage still moves at the same rate, but its attack strength would be halved (dead men can't pull triggers), whereas a tank that has taken 50% damage might have its move rate cut in half, but the main gun will attack at full strength until the unit is destroyed. You'd need some sort of flag to indicate that a particular stat is Reduced by Health Damage to implement it with the least amount of coding, I'd assume.

    Might be something to consider for TBTKv4?

    Thanks for the quick reply!
     
  17. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    It's not difficult to track the unit facing. You can get the value from the unit transform directly. It's the additional work to allow player to control that. It's hard to add that on top of existing user input without complicate things. Plus you will almost certainly need to add visual indication to unit facing and any action limitation due to the direction.

    The individual system on unit is a very subjective take. the design of such system can be very simple to down right pseudo realistic simulation. I don't think I can come up with a one size fit all solution to it.
     
  18. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    191
    Getting a few errors when I press "Restart" after a battle. Not sure why.

    Could be something simple but maybe I'm just not seeing it.
     
  19. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    I'm not getting any error. Have you modified the code in any way?
     
  20. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    191
    Not really. I changed one UI from "AI's Turn" to just "" and had Unity update some of the terms: ( case EventType.KeyDown: from case EventType.keyDown:).

    I changed the Timescale to 10 to experiment with other stuff. Added your humanoid example. Turned off some UI elements but then turned them back on to see if that was causing it.

    I have some other assets but I don't think they would be messing with the scene.
     
  21. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    Alright, I'm not sure what exactly has gone wrong in your case. But you should be able to get rid of the error by adding if(obj!=null) just before line-78 and if(canvasGroup==null) yield break; just before line-87 in _UI.cs.
     
    Stexe likes this.
  22. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    191
    Awesome. Seems to have fixed the errors, but when I click Restart to redo the combat the Timescale resets back to normal or something?
     
  23. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    Yes, the timescale will be reset back to 1 whenever you use the default menu to load or restart a scene.
     
  24. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    191
    Found it. Any reason for that inclusion?

    Code (CSharp):
    1.         public static void RestartLevel(){
    2.             Debug.Log("Restart level");
    3.             string lvlName=UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
    4.             UnityEngine.SceneManagement.SceneManager.LoadScene(lvlName);
    5.             Time.timeScale=1;
    6.         }
     
  25. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    Whenever the pause menu or the game over screen is bought up, the game is paused by getting its timescale set to 0. Without resetting it back to 1, the next scene will simply be freeze. Comment out that line and you'll see what I mean.
     
  26. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    191
    I did comment it out, but Pause hasn't actually been Pausing for a while. I figured that's how it worked but I didn't need that functionality so just ignored it.
     
  27. Liberation85

    Liberation85

    Joined:
    Apr 16, 2019
    Posts:
    52
    @songtan What is the best way to spawn units based on the turn count?

    So far I have made a list that I can assign gameobjects to in the inspector which I deactivate inside the hierarchy. After a certain amount of turns my code uses SetActive(true) to activate them.

    This works fine for objects not assigned with the unit.cs and added to the database.

    Any ideas on how to make this work or a possible better solution?
     
  28. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    You can refer to the code in Ability.cs, specifically about adding unit to game during runtime, around line-202 (just look for (type==_Ability.SpawnUnit)).

    So you can keep doing what you are doing, except instead of activating deactivated object, you run that code to instantiate the unit and add it to the game. The only thing missing is you will need to know which node you want to place the unit on.
     
    Stexe likes this.
  29. Tarrasque

    Tarrasque

    Joined:
    Jan 5, 2015
    Posts:
    21
    I tried to add more than one type of obstacle (two different full walls, for example) and it doesn't allow me to place it. Only one button is active - with the first element from the list? picture1.png
     
  30. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    Thanks for letting me know. Apparently there's a bug with the editor. I've already fixed it and sent a package to you.
     
  31. seb-pj

    seb-pj

    Joined:
    Feb 18, 2018
    Posts:
    2
    Hi Songtan !

    I haven't bought your asset yet, but I'm planning to work on a RPG project with a turned based battle system, and yours seems to be great.
    I have one question before stepping up : I would like to create a 2D game, which could look like Octopath Travelers, and the battle system that I'd wish to use would be like your hex grid, but with a fixed camera on the side and 2D characters on the battlefield.
    My question may look stupid because I haven't started anything and I don't know how to program, but is this compatible ? Can I use 2D elements on your asset ?

    Here is how it looks like, I would just like to add a, hex grid :
    https://blogs.forbes.com/olliebarder/files/2019/04/octopath_traveler_pc.jpg
     
  32. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    Yes. You can definitely use TBTK with 2D asset for fixed perspective camera. You will probably need some slight modification to get it to work (mainly just to make sure the units doesn't rotate themselves like they would in a 3D setting). I can help you with that.
     
  33. seb-pj

    seb-pj

    Joined:
    Feb 18, 2018
    Posts:
    2
    Fantastic ! Thanks a lot for your fast reply, Songtan !
    I should start to work on it next year, I might have to request some help if I encounter any issue.

    One last question : what's the difference between TBTK-2 et TBTK-3 ? Can I use the latest version (3) for my project ?
     
  34. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    TBTK3 is the latest iteration. It's more powerful and more optimized. It's also the version where any new feature will go, if there's any. There won't be any new feature for TBTK2 except bug fixes and compatibility update.

    If you already have 2, you can pay the difference and upgrade to 3.

    Technically both can be used for your project. However I would recommend 3. It's simply superior in every way and it's a lot easier if you want to do any code modification.
     
    Stexe likes this.
  35. Liberation85

    Liberation85

    Joined:
    Apr 16, 2019
    Posts:
    52
    @songtan What was the fix for the obstacle prefab selection?
     
  36. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    I can't quite remember but I've sent a package containing the fix to you.
     
  37. Liberation85

    Liberation85

    Joined:
    Apr 16, 2019
    Posts:
    52
    @songtan Thanks for that, worked a treat.

    A new question, what is the best way to disable an ability during run time?

    My example being, a unit of 3 men with one being the medic. As the unit strength goes down the unit loses men, so when the medic is removed I would like the field repair ability to be removed as well.

    I have a vague idea how to do it, but it seems pretty hacky and I have no idea how to reactivate this ability when the unit itself is healed.
     
  38. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    You can simply add a line of condition check in Ability.IsAvailable(), in Abilty.cs. As long as you don't return 0, the ability will not be available. The UI should automatically disable it.

    For your example, assume the unit strength is measured by hp, you can simply put in something like if(srcUnit.hp<5) return 7; will do.
     
  39. Liberation85

    Liberation85

    Joined:
    Apr 16, 2019
    Posts:
    52
    Thanks @songtan that work pretty well and I learnt a lot from that.

    One other question, I need to trigger a script that is attached to the gameobject prefabs when these units are selected, as I don't want them running all the time...

    For example

    If(ThisUnitSelected == true)
    {
    Do stuff
    }

    However I can't find a way of checking that. Any suggestions?
     
  40. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    UnitManager.GetSelectedUnit() should return the current selected unit, if there's any. You can use that to check against the unit in question.
     
  41. sisko89

    sisko89

    Joined:
    Mar 8, 2019
    Posts:
    20
    I'm having trouble with the spawnUnit ability.
    The spawned unit appears, and iddle animation works. But it doesn't have a health bar, can't be attacked, other units can walk through it or stand in the same node, and its turn never comes.
    I checked the UnitManager object and it doesn't show up in the "all unit list".
    Any idea how to fix it? Thanks!
     
  42. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    Thanks for letting me know. I'm afraid there's no simple fix for this bug. The code for adding a unit in UnitPerTurn mode is missing entirely due to my oversight. I'll fix this but it will be two weeks before I can do this (I'm travelling atm, away from my work pc).

    You can send me an email if you want so I can send you the fix in advance as soon as it's done. Sorry for the inconvenience and thanks for your patient.
     
    Stexe likes this.
  43. sisko89

    sisko89

    Joined:
    Mar 8, 2019
    Posts:
    20
    Thank you for your quick reply. Nothing to be sorry for, the asset works great overall!
    Please send the fix to sisko89@gmail.com whenever you have the time. Meanwhile I'll keep working on other features.
    Thanks a lot!
     
  44. sisko89

    sisko89

    Joined:
    Mar 8, 2019
    Posts:
    20
    One more question... how can I make an ability work only if there's direct line of sight with the target? I mean not being able to use the ability if there's a full obstacle in between. I checked the "require line of sight" in the ability manager but doesn't seem to work.
     
  45. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    Checking 'require line-of-sight' should do the trick as far as I remember. If not, Can you please send me a screen-shot of an instance where it fail to work. I'll try to figure out why.
     
  46. sisko89

    sisko89

    Joined:
    Mar 8, 2019
    Posts:
    20
    It fails in every instance I try... I even tried creating a new project with a fresh install of the script, changed nothing except adding 'require line-of-sight' to stun shot and it can still be used through both full obstacles and full walls.
    Could you please test it yourself and confirm if it works? Thanks
     
  47. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    I ran some test and I might have found out the reason why it doesn't work. I have just sent a potential fix to your inbox. Please let me know if that helps.
     
    Stexe likes this.
  48. artyrambles

    artyrambles

    Joined:
    Jan 10, 2014
    Posts:
    18
    Hey there @songtan , I'm considering buying the TBTK-3. But first I'd like to know more about the factions. Is only one faction possible or could I make multiple factions for the player to choose from at the beginning of the game?
     
  49. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    You can have multiple factions. However by default you will have to specify which faction are the players' and which are controlled by AI. That said, it should be relatively easy to add something to allow the player to choose a faction before the game starts.
     
  50. artyrambles

    artyrambles

    Joined:
    Jan 10, 2014
    Posts:
    18
    Sweet, thanks for the info!
     
unityunity