Search Unity

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

TowerDefense ToolKit 4

Discussion in 'Assets and Asset Store' started by songtan, 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. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    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:
    5
    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. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    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:
    126
    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:
    6
    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. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    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:
    5
    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. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    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:
    5
    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. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    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:
    5
    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. songtan

    songtan

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

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

    2b. Yes.
     
  16. RitsumeiWang

    RitsumeiWang

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

    Vaupell

    Joined:
    Dec 2, 2013
    Posts:
    250
    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. songtan

    songtan

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

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

    colour

    Joined:
    Nov 15, 2011
    Posts:
    2
    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. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    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:
    2
    thanks
     
unityunity