Search Unity

TowerDefense ToolKit 4

Discussion in 'Assets and Asset Store' started by Song_Tan, Apr 18, 2012.

  1. lpye

    lpye

    Joined:
    Aug 2, 2012
    Posts:
    30
    @songtan: I would like to create an ability that, as an example, if it has a radius of 3 units, will attempt to create a tower on all available build platform nodes within that 3 unit radius.

    Do you have any suggestions on how I might go about this?

    EDIT: Adding my current code so you can see what I'm doing. It seems to work but I'm a little deep into the inner workings and wanted to make sure I wasn't misstepping. The idea is this gets added as an "On Activation" object, for a custom ability.

    Code (CSharp):
    1. public class MassCreateTowersOnActivate : MonoBehaviour, IAbilityActor
    2. {
    3.     public UnitTower towerToMassCreate;
    4.     public bool ignoreTowerCost = true;
    5.  
    6.     public void PerformAbilityAction(Ability ability)
    7.     {
    8.         if (towerToMassCreate == null) return;
    9.  
    10.         Debug.LogWarningFormat("MassCreateTowersOnActivate.PerformAbilityAction");
    11.  
    12.         // find all buildplatforms inside the radius, if we can
    13.         Collider[] cols = Physics.OverlapSphere(transform.position, ability.GetAOERange());
    14.         List<BuildPlatform> platforms = new List<BuildPlatform>();
    15.         foreach (Collider c in cols)
    16.         {
    17.             BuildPlatform bp = c.gameObject.GetComponent<BuildPlatform>();
    18.             if (bp != null)
    19.             {
    20.                 platforms.Add(bp);
    21.             }
    22.         }
    23.         // for each buildplatform, return all available buildable nodes if we can
    24.         foreach (BuildPlatform plat in platforms)
    25.         {
    26.             NodeTD[] nodes = plat.GetNodeGraph();
    27.             if (nodes == null || nodes.Length < 1) continue;
    28.             foreach(NodeTD node in nodes)
    29.             {
    30.                 if (Vector3.Distance(node.pos, transform.position) < ability.GetAOERange())
    31.                 {
    32.                     // for all nodes within radius, attempt to build the tower
    33.                     SelectInfo sInfo = new SelectInfo(plat, node.ID);
    34.                     if (!(sInfo.HasValidPoint() && sInfo.AvailableForBuild() && sInfo.CanBuildTower(this.towerToMassCreate.prefabID)))
    35.                     {
    36.                         continue;
    37.                     }
    38.                     TowerManager.BuildTower(this.towerToMassCreate, plat, node.ID, !ignoreTowerCost, false);
    39.                 }
    40.             }
    41.         }
    42.     }
    43. }
     
    Last edited: Jun 12, 2021
  2. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Looks about right. But I would suggest you do look into InitPlatform() in TowerManager where the all the BuildPlatform is initialized. You can store the list in the function so you don't need to do a Spherecast to get all BuildPlatform in the scene. Just a slight optimization tip.
     
  3. RitsumeiWang

    RitsumeiWang

    Joined:
    Jun 7, 2021
    Posts:
    13
    Sry for asking a basic question
    how can I start debugging mode with vs
    I tried but it said can't start with output type of class library
    then I changed it as window and console app also didn't work for me
    is there wrong steps I haven't set or something else?
     
  4. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Hm... I'm sorry but I'm not sure if I can help here. I don't use vs myself and I'm not familiar with it. What you need is to get vs working with unity in general. You will probably have better luck asking that in 'Editor & General Support' or 'Scripting' section of the forum.
     
  5. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    first thing that comes up in a simple google search:
    https://docs.unity3d.com/Manual/ManagedCodeDebugging.html
     
  6. mhonnibal

    mhonnibal

    Joined:
    Feb 22, 2021
    Posts:
    11
    i do this all the time to song :p
     
  7. hzkinunity

    hzkinunity

    Joined:
    Jul 4, 2021
    Posts:
    2
    Hi, your TDTK is a very useful plugin

    Now I have two requirements for your help:

    1. If I want to change the HP calculation formula of TDTK, where can I find the code

    2. My store wants to increase Perk resources after pressing the button. How to do this?

    Thank you very much!
     
  8. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Thank you!

    1. Do you mean HP calculation when an attack hit? Or just the HP of a particular unit? The you can find the former in UStats.cs, in the class AttackInfo, where the damage is calculated. Then in Unit.cs, ApplyAttack(), where the damage value is applied. The total hp of a unit is given by the function GetFullHP() in Unit.cs. You should be able to trace the rest of the code from there.

    2. You can increase the perk resource by simply calling PerkManager.GainRsc(amountGained);.

    Hope this help.
     
  9. hzkinunity

    hzkinunity

    Joined:
    Jul 4, 2021
    Posts:
    2
    cool,GetFullHP() and GainRsc are what i need,
    it helpful,thanks a lot!
     
  10. RitsumeiWang

    RitsumeiWang

    Joined:
    Jun 7, 2021
    Posts:
    13
    Hi!
    As I tested flying bypass option and I found that creep can walk across tower even without that option, is that mean tower has no block effect for beeps?
    For my design I want to creep walk as path points and stop as it touch towers on its road. Also creep will retarget the block tower as high priority and once tower is destroyed it can walk again. Any ideas or solutions?
    Also for walkable one, as I assign the waypoint to where tower is, it can walk across tower without checking walkable option. So this option works for what kind of situations?
     
  11. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    From what I can gather, you are having your creep move along a set of fixed waypoints with no platform? Fyi, when there's no platform, the creep will just follow the waypoints. They will not stop for anything. If you want the tower to block the creep, you will have to get the creep to move through the build platform where the tower is built. The 'flying bypass' option is for flying creep to ignore tower when they move across a builtplatform.

    The framework doesn't really support a scenario where you can place tower to completely block the path, forcing the creep to stop. Best you can do is keep using a fixed path and enable 'stop to attack' on your creeps. This will force the creeps to stop when they try to attack a tower. That said, they will stop to attack any tower in range, not just the towers that are 'in the way'. You can probably resolve this by setting the attack range of the creeps to minimal so they only detect towers that are directly in their way.

    Hope this help.
     
  12. RitsumeiWang

    RitsumeiWang

    Joined:
    Jun 7, 2021
    Posts:
    13
    Thanks!
    it is very helpful for your advice !
    but for the flying bypass one.
    I do another test as I used Demo_Linear scene and make things as picture like.
    Those transports can move through towers without flying bypass.
     

    Attached Files:

  13. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    You misunderstood. Flying bypass (or any other path-finding related setting) only applies when the creep are moving on a build-platform (the grid where you build tower), as in the build-platform are assigned as one of the waypoint on the path (see other demo scene). Again, when the waypoints on the path is just a series of empty transforms, the creep will just move through the waypoints without stopping.
     
  14. RitsumeiWang

    RitsumeiWang

    Joined:
    Jun 7, 2021
    Posts:
    13
    I am sry for misunderstanding flying bypass.
    Actually I also want more details about flying units(the check box one in creep editor)
    Can I take flying things as
    1.if the path only have serval points creep will ignore any tower/obstacle whether it is flying unit or not
    2.if the path contains build-platform and when creep moving on it
    a. The one with flying tag can ignore tower/obstacle and move through them
    b. One without flying tag will avoid tower/obstacle and make a new route
    PS: I use demo branching path and found that choice a seems impossible whenever creep will do choice b
     
  15. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    1. yes

    2a. Yes when you have 'flying bypass' enabled.

    2b. Yes.
     
  16. RitsumeiWang

    RitsumeiWang

    Joined:
    Jun 7, 2021
    Posts:
    13
    Thanks ! That helps a lot !!!
     
  17. Vaupell

    Vaupell

    Joined:
    Dec 2, 2013
    Posts:
    302
    Hi @songtan, I haven't used this asset since version 2.2.4f2 8 years ago. ;)

    Now my path have lead me back to TDK, one question before "rediscovering" TDTK-4,
    I saw you posted a video some 4 years ago, around alternate pathing, so if a path is blocked it will try to update the route.

    Has this been implemented, or was it just a fun test?

    Reference video:
     
  18. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Welcome back!

    Yes, it has been implemented in TDTK-4.
     
    Vaupell likes this.
  19. colour

    colour

    Joined:
    Nov 15, 2011
    Posts:
    4
    is there a tutorial or documentation?

    Having trouble creating new units and making creeps spawn from two paths at once
     
    Last edited: Jul 19, 2021
  20. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Yes. There's a pdf documentation that comes with the package. It's not exactly a tutorial but it does explain how most things work in the framework.
     
  21. colour

    colour

    Joined:
    Nov 15, 2011
    Posts:
    4
    thanks
     
  22. mhonnibal

    mhonnibal

    Joined:
    Feb 22, 2021
    Posts:
    11
    Song im almost done with my game thanks so much for your help!

    Am i allowed to link to it?
     
  23. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Sure. I don't see any harm doing that.

    Good luck with it btw!
     
  24. mhonnibal

    mhonnibal

    Joined:
    Feb 22, 2021
    Posts:
    11
  25. ceprowler

    ceprowler

    Joined:
    Oct 24, 2020
    Posts:
    18
    EDIT: Disregard this post. There is a free tool in the unity store called Text to Text Mesh Pro Upgrade Tool that did the upgrade perfectly. Leaving this post up for anyone else that might run into this issue.

    In an effort to get the UI to look a little cleaner I was changing the default UI text components for Text Mesh Pro text components and it was working great, until I got to items that update in code like wave count, life, etc. Has anyone updated to Text Mesh Pro successfully and how difficult was it? Also, since I've been unsuccessful in making the update if you have gotten it to work can you post and example of what changes need to be made? I appreciate any help.
     
    Last edited: Sep 6, 2021
  26. xmonster0

    xmonster0

    Joined:
    Oct 24, 2020
    Posts:
    15

    sound groups are easily managed by master audio asset
     
  27. ceprowler

    ceprowler

    Joined:
    Oct 24, 2020
    Posts:
    18
    Songtan, I hope you are well. I'm having an issue where the radius of AOE towers does not properly update the range indicator during placement of the tower. The damage calculations adjust properly for the range listed, even though they don't match the indicator. Interestingly, if I change the tower to be a dual type AOE and Turret and then adjust the range for both types to the same range it will adjust properly even if I uncheck Turret and make it only an AOE tower again. I have tested this in a brand new project to verify it still happens with a clean project. Can you take a look when you get a moment and verify as well as advise on how to fix this issue?
     
  28. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Thanks for pointing this out. This is an oversight from me when doing the previous update. You can fix this by modifying the script RangeIndicator.cs. Specifically, changing line69 from:

    radius=unit.GetAttackRange();

    to following:

    if(unit.IsTurret()) radius=unit.GetAttackRange();
    else if(unit.IsAOE()) radius=unit.GetAttackRange_AOE();
    else if(unit.IsSupport()) radius=unit.GetAttackRange_Support();
    else if(unit.IsMine()) radius=unit.GetAOERange_Mine();
    else radius =0;

    Please let me know if you have any problem with it and very sorry for the trouble.
     
  29. ceprowler

    ceprowler

    Joined:
    Oct 24, 2020
    Posts:
    18
    Thank you for the quick response. That fixes it perfectly!
     
  30. PetarCukl

    PetarCukl

    Joined:
    Feb 13, 2021
    Posts:
    3
    Why some platforms are under the surface? How to solve this issue? Also particle systems on it is under the surface. Terrain and surface I'm keeping it on Y = - 0.01 but platforms on Y = 0
     
  31. Logos-180

    Logos-180

    Joined:
    Feb 18, 2017
    Posts:
    4
    Does your Toolkit allow to spawn multiple waves at the same time?
     
  32. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm afraid I don't really understand your question. I tried putting a terrain in my test scene with Y=-0.05 and everything seems fine to me. Can you explain what's wrong? Some screenshot would help.

    You can only have one way at a time. But within a single wave, you can spawn different group of creep with different spawn timing that takes different path. A 'sub-wave' so to speak.
     
  33. Logos-180

    Logos-180

    Joined:
    Feb 18, 2017
    Posts:
    4
    So if i wanted to have a wave, that spawned 5 land units on one "route" and 5 air on another, would that be possible? sorry if you already answered, jsut trying to understand
     
  34. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Ah. I see the spelling mistake in my respond. What I meant to say is 'You can only have one wave at a time'. Yes, you can have a group of land unit on one route and another group of air unit on another route, all within a wave. See the screen shot attached. You can have as many 'sub-wave' as you want within a single wave. Each 'sub-wave' can have their own unit type to spawned, path to take, spawn timing, etc.
     

    Attached Files:

    • Wave.png
      Wave.png
      File size:
      21.1 KB
      Views:
      292
    Logos-180 likes this.
  35. Logos-180

    Logos-180

    Joined:
    Feb 18, 2017
    Posts:
    4
    That's brilliant. i will grab this one on pay day =).
     
  36. Logos-180

    Logos-180

    Joined:
    Feb 18, 2017
    Posts:
    4
    OH another thing, is it possible to make the creeps walk less uniform than a straight line? like some out to the side, maybe next to each other even
     
  37. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Yes. You can assign a random offset range to the path so each individual units moving on it will follow the intended waypoint with a random offset. Making their positioning less uniform.
     
    limo and Logos-180 like this.
  38. nnoom1986

    nnoom1986

    Joined:
    Jan 9, 2018
    Posts:
    27
    Hey @songtan , something seems to be up with the Effects. In the Demo_Linear, if you set Stun_3sec to a Duration of 0 and attach it to an ability to test it, it still persists for roughly 1 second. This additional second seems to be added to any time you put in there.

    Also, Support doesn't seem to be working properly. In the same demo, if you set the Transport to Support with a Support Effect of Range Buff, it doesn't seem to do anything.

    I noticed the reverse in my game, where Support ignores all duration and radius and just applies immediately and for the entire time.
     
    Last edited: Nov 5, 2021
  39. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Thanks for letting me know. I'll look into it and upload a fix soon.

    Edit: The fix is up. Please let me know if you have any more problem.
     
    Last edited: Nov 5, 2021
    nnoom1986 likes this.
  40. Geoffc

    Geoffc

    Joined:
    Feb 4, 2013
    Posts:
    39
    Hi, @songtan I found something that is confusing, could be a bug? When you set the Dynamic Offset on a path in the inspector window, it will default back to 0.45. I noticed in the path.cs script there is some code there on line 278 setting it to 0.45. It looks like this line of code will override the inspector settings. I am using version 4.1 f2 (November 06, 2021). Do you have a fix for this? Every path will need to have the same dynamic offset if it is changed in code. I should also note that the value entered in the inspector is being stored correctly in the inspector but not being used at runtime.
     
  41. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    The value is limited to 45% of the grid size value you use in TowerManager, which is default to 1. That set your limit at that's why the 0.45.

    The reason of this limitation is being on a grid, any dynamic offset higher than 45% of the grid size could send the so far of the path they move in the neighbouring nodes to the path. If you want to remove this, simply remove line278 on Path.cs
     
    Geoffc likes this.
  42. Geoffc

    Geoffc

    Joined:
    Feb 4, 2013
    Posts:
    39
    In a 2D setup, the towers are being rotated even if I rotate the prefab. How can I change this orientation? I have changed the buildplatform script to align the platform from 90 to 0 and that is working well now but I can't find how and where the orientation of a tower placement is being handled.
     
  43. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    The rotation of the tower are set when they are being instantiated. There are two functions that you need to look at depends on what build mode are you using.

    If you are using DragNDrop, the rotation of the tower is set in TowerManager.CreateDragNDropTower().

    If you are using PointNBuild, the rotation of the tower is set in TowerManager.BuildTower().
     
  44. Geoffc

    Geoffc

    Joined:
    Feb 4, 2013
    Posts:
    39
    In TowerManager script I changed
    GameObject obj=(GameObject)Instantiate(prefab.gameObject, new Vector3(0, 999, 0), Quaternion.identity);

    to:

    GameObject obj =(GameObject)Instantiate(prefab.gameObject, new Vector3(90, 999, 180), Quaternion.identity);

    This I still don't see a change. Is that the right place? I am using drag and drop mode.

    I have tried to rotate it:
    UnitTower.transform.Rotate(90.0f, 0.0f, 0.0f, Space.World);

    But I'm getting an object reference error doing it this way.
     
    Last edited: Nov 9, 2021
  45. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    That's the line but you are changing the tower position instead of its rotation. Try

    GameObject obj=(GameObject)Instantiate(prefab.gameObject, new Vector3(0, 999, 0), Quaternion.Euler(90, 0, 180));
     
  46. Geoffc

    Geoffc

    Joined:
    Feb 4, 2013
    Posts:
    39
    Ok, thanks, it works now :) So vector3 is the transform position, and we are following after that with the transform rotations as Euler angles.
     
  47. Geoffc

    Geoffc

    Joined:
    Feb 4, 2013
    Posts:
    39
    Where can we do this for the creeps? I have found a line in UnitCreaps that looks like it is the generation line:
    GameObject unitObj=ObjectPoolManager.Spawn(prefab.gameObject, spawnPos, thisT.rotation);
    But my attempt at it did nothing:
    GameObject unitObj = ObjectPoolManager.Spawn(prefab.gameObject, spawnPos, Quaternion.Euler(90, 0, 180));

    Am I even on the right track here? If the objects are rotated this way, will the tracking still work?
     
  48. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Creep changes rotation according to where they are heading. What you are setting here is just the initial rotation. You will also need to disable the 'Face Traveling Dir.' option on the creep prefab.
     
  49. Geoffc

    Geoffc

    Joined:
    Feb 4, 2013
    Posts:
    39
    With:
    GameObject unitObj = ObjectPoolManager.Spawn(prefab.gameObject, spawnPos, Quaternion.Euler(0, 90, 90));
    and 'Face Traveling Dir' unticked, I still have the default rotation. Seems to be getting overridden somewhere, is the a place that it is resreshed?
     
  50. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Sorry, I misread earlier. What you modified is for spawner creep (when creep spawn other creep). You will also need to modify the one in SpawnManager.cs, where the actual spawning of new creep on SpawnEditor happen. That's line247 -
    GameObject unitObj=ObjectPoolManager.Spawn(creep.gameObject, path.GetSpawnPoint(), Quaternion.identity);