Search Unity

TowerDefense ToolKit 4

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

  1. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    First, it's just me. There's no team. :)

    I think you will need to understand how the script control the animation. Since you use your custom controller, so I take it you know in most case we set up the state machine on the animator controller. From there we can set which animation clip to play in which state and what are the condition (a set of variables) to trigger what states. With this in mind, there are 2 things that the default TDTK controller do. First the script uses the animations listed in the TowerEditor is used to replace the animation in the TDUnitController. Then the script trigger the required animation state in TDUnitController using the preset variables. Now because the script is hardcoded, it only works with TDUnitController. The name of the variables and states of the controller has to match what is written in the script.
     
    Riviere_N likes this.
  2. Riviere_N

    Riviere_N

    Joined:
    Jul 14, 2022
    Posts:
    9
    I know I was missing something very basic! well 2 things:
    1. the one man army you are! :b
    2. How ti was hard-coded.
    Thanks a million!
     
  3. Big_CEO

    Big_CEO

    Joined:
    Nov 1, 2023
    Posts:
    2
    Hi There,
    I love this template so much! I've tried adding a character that you can move around who places the turrets, but currently when I try to make it so the platforms are able to be walkable, it breaks the maze pathing and turrets can no longer be placed too, is there an easy way to go about solving this? I'm pretty new to unity so I'm a bit lost.

    Edit: I was also wondering if its possible to have a way to just have 1 big buildable grid, with waypoints along it for the enemies to move along and find the fastest way towards, as everything I try I can only get it so the waypoints go to the centre of any buildable platform. Whereas I was looking for the platform itself to have various waypoints on it that arent just the centre.

    Thanks So Much!
     
    Last edited: Nov 7, 2023
  4. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Thankyou. And sorry for the slow response. My access to internet is limited this week as I'm traveling.

    To answer your first question, I have to ask what have you done in adding a character and to make it ti move. My guess is you have accidentally added some colliders that interfere with the pathfinding. Fyi, the code uses collider detection to establish the walkable area on the grid.

    For your second question. You can have the creeps move through multiple paths. Each path goes back to the same platform before continuing to the next path. Using this setup, you can have tbe creeps move to a particular point of the platform, exit, move to the next path, then enter the platform again at the same point. In play, this will look like the creeps move through various checkpoints on the platform.

    Hope this helps.
     
  5. Big_CEO

    Big_CEO

    Joined:
    Nov 1, 2023
    Posts:
    2
    Thank you so much for the reply! Yes I was having to use a mesh collider to make it walkable so I'm not sure how to remedy that, I tried making an alternate walkable platform but the same still occurred

    Edit: I figured out the second problem.

    Thanks once again for the advice!
     
    Last edited: Nov 8, 2023
  6. Niroan

    Niroan

    Joined:
    Jun 16, 2019
    Posts:
    115
    Is it possible to create a terrain and make the user drag and drop towers where they want to? Im getting "Invalid Build Point" from the terrain. But if i remove the collider from the terrain im able to build. But i would love to have the terrain with trees. So the the user can build on the terrain but not on the tress.
     
  7. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Sorry for the slow response again.

    Change the layer of the mesh collider to layer-31, the designated terrain layer (refer to TDTK.cs). The collider detection algorithm will then ignore the collider in question. You can keep the mesh collider for your character navigation without it interfering with the platform pathfinding.

    I'm afraid you can't build directly on the terrain with terrain collider. You can only build on the 'build platform'. Unless you want to drastically change the code, the best way to get around this is create a grid of platforms, then align them to the terrain. Alternatively you can try enable the 'Free-Form' mode in TowerManager. That will allow you to build on any collider that has been assign the 'Terrain' layer. However, the tower will not be able to block any path in this mode.
     
    Niroan likes this.
  8. Riviere_N

    Riviere_N

    Joined:
    Jul 14, 2022
    Posts:
    9
    HI Song! (and other forum members :))
    "Effects" question: When I assign a creep to apply an effect after successfully hitting a tower, it seems the effect gets applied to the creep and not to the tower it just shot. :confused:

    but when a tower applies the same effect to the creep after a successful hit, it works like a charm.

    Any hints into how to ensure the creep's effect get applied top the tower?
     
  9. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I have to ask how do you have a creep apply the effect when attacking? It works fine for me. For example, using the default 'Tank' prefab, this is how I add the default stun effect to its attack.

    upload_2024-1-21_16-14-10.png
     
  10. Riviere_N

    Riviere_N

    Joined:
    Jul 14, 2022
    Posts:
    9
    Thanks as usual for the quick reply.

    Yep, that's how I have it :confused: . Hmm
    upload_2024-1-21_11-5-34.png

    OK, weird. it works:
    Tower hitting creep,

    but creep hitting tower doesn't....

    So it may be something in:
    A) my tower-to-creep SO colliders,
    B) the Tower collider itself,
    C) the SO properties,
    etc..
    Dam, ok, :(
     
  11. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Right. I'm not sure what's wrong tbh. According to the code, as long as the attack 'hit', the effect should apply, Collider should have no effect in this.

    I suggest you try this. First, get the default creep prefab, unaltered, and just give it a stun effect and have it attack a default tower prefab. See if that works. Then have that creep attack your tower tower, then have that creep use your custom so. And you can try using the default prefab with a stun effect to attack your tower. We can see what component breaks the function.

    Also you might want to check the 'Effect Immunity List' on the tower prefab (on inspector only) to see if you haven't accidentally set it to immune to something.
     
    Riviere_N likes this.
  12. Riviere_N

    Riviere_N

    Joined:
    Jul 14, 2022
    Posts:
    9
    Never mind, wrong Layers were used :oops: and was giving some weird results. My bad/sorry/thanks.
     
  13. Niroan

    Niroan

    Joined:
    Jun 16, 2019
    Posts:
    115
    Hi @Song_Tan

    Is it possible to get DragAndDrop working as actually drag and drop?
    Right now you have to click build button then drag and drop.

    On mobile device this does not work at all, then user have to click button, then drag the tower and release.
    Like Click = Spawn, Click and hold to place it where you want. Then release.

    How can we fix this so it just works as actually drag and drop? Would be amazing to get fixed
     
  14. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Have you tried enable 'Touch Mode' on UI? That would have the tower spawn as soon as you press on the button. Allow you to start dragging without lifting your finger.
     
  15. Popcony

    Popcony

    Joined:
    Apr 14, 2014
    Posts:
    17
    I'm building a game centered around elemental types. I created a Damage and Armor table in the 'damagetableeditor' and I was wondering how to implement a way to 'choose' an element to assign to a tower. I thought It could be done via upgrades or effects. How do I change a tower's DamageType from 'Normal' to 'Red' via a 'perk' or special 'upgrade' or 'effect'? Maybe an effect you can equip to a tower. IDK, just wondering if I need to create a support tower that sits behind or in range of another tower to change the type via an effect.

    -P
     
  16. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    You assign the damage/armor type to a unit (towers and creep) using the their corresponding editor. TowerEditor for towers and CreepEditor for creep. Unfortunately you can't change a unit damage/armor type during runtime. The only way you can do that, for tower anyway, is just through upgrade. That is if you set the next upgrade to have different damage/armor type.
     
  17. Popcony

    Popcony

    Joined:
    Apr 14, 2014
    Posts:
    17
    Can those 'upgrades' be done in a non-linear way? Like start with NORMAL type damage and then choose to upgrade the tower to be a blue or red or green variant?

    -P
     
  18. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Of course, each tower can have more than one upgrade option (up to 3 if I remember correctly). You just need to create a new tower prefab for each option. You can see the default tower prefab for example. Most of them can be upgraded to other prefabs.
     
  19. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    75
    hello i just pulled this asset out of the closet and i started it up and i used the demos and i cannot place a tower. i can choose a tower but i cannot place them and i get a camera error when opening the scenes, im also using the new input system if that matters upload_2024-2-12_15-16-51.png
     
  20. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Sorry for the slow respond. I've been away for the past 2 days.

    Can I know what version of Unity are you using? I tried it on Unity as latest as 2022 and everything seesm to be working right out of the box.

    The error that you are experiencing is just a warning about an obsolete component. It shouldn't break anything and should resolve itself after you save the scene.

    I'm not familiar with the new input system but as far as I know it shouldn't affect the existing code. Speaking of which, TDTK uses the default (old) input system so you don't need the new input system for it to work. Perhaps you can try import the package to a new project with the new input system and see fi that works?
     
  21. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    75
    upload_2024-2-14_16-21-57.png
    for the other tools in my system it requires the new input system im not familiar with ti also this seems like a raycast issue to me . the other tool is the game creator 2 visual scripting system so its kinda vital
    upload_2024-2-14_16-21-57.png
     
    Last edited: Feb 14, 2024
  22. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    75
    New Install worked ,new input system and all ..one of those gremlins ..thanks

    upload_2024-2-14_17-41-26.png

     
  23. culmastadm

    culmastadm

    Joined:
    Mar 5, 2020
    Posts:
    7
    Has anyone added gamepad support to this yet?
     
  24. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm afraid there's no gamepad support for TDTK. However I'm not sure if anyone else has done that.
     
  25. culmastadm

    culmastadm

    Joined:
    Mar 5, 2020
    Posts:
    7
    I have been working on it over the past few days. Almost there. I have a virtual mouse controlled with the gamepad. Just have to detect between the mouse cursor and the virtual mouse when clicking on the tower selections, and that is all.
     
  26. Riviere_N

    Riviere_N

    Joined:
    Jul 14, 2022
    Posts:
    9
    Hey Song,

    I need to bounce something of you as my towers are getting some "weird" damage.

    Scenario 1: Creeps are in the field and towers are attacking them. I deploy an effect (via an Ability) into the field to damage enemies. It damages enemies as intended.

    Scenario 2: Creeps are in the field and towers are attacking them. Enemies attack (once ) any tower. I deploy an effect (via an Ability) into the field to damage enemies. It damages enemies as intended.

    Scenario 3: Creeps are in the field and towers are attacking them. Enemies attack (twice or more) any tower. I deploy an effect (via an Ability) into the field to damage enemies. It damages enemies as intended but also all towers in the filed!

    I've tried:
    A) via Inspector to make tower "immune" to the effects (using the prefab ID of the Effect.)
    B) ensuring all towers are in the Tower layer ( :confused: )
    C) the Abilities are all set to : Target Type : Hostile and do NOT require target

    Any words of wisdom?
     
    Last edited: Mar 14, 2024
  27. Riviere_N

    Riviere_N

    Joined:
    Jul 14, 2022
    Posts:
    9
    OK, after a day + of extra debugging, seems to be caused by AOE vs Effect modifier. I had been using AOE. If I use Effect modifier instead the behaviour is what one would have assumed/expect upload_2024-3-14_9-50-0.png
     
  28. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Sorry for the slow response. I've been away for most of last week.

    Unless I miss understood the situation, I think what happen is intended. The 'Stats' are values used to alter the target unit stats. When the effect is applied to the hostile unit, they stats configuration gives them aoe ability that damage the towers.
     
  29. tistik

    tistik

    Joined:
    Mar 15, 2012
    Posts:
    7
    Hello. This asset looks amazing, but I have a question. Am I right to assume that it does not allow the player to build paths themselves? And if so, would there be a workaround to make it possible?
    The idea I have in mind is to let players decide where to place paths in addition to the traditional tower placement gameplay.

    Thank you in advance
     
  30. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Unfortunately no. As for workaround, It's very much depends on how you want the pathing to work. But honestly, even with the simplest execution in mind, I wouldn't call any of the potential solution 'workaround' by definition. You will need to do a bit of coding to get the mechanic to work no matter how you cut it. Then there's the UI that support the feature, which will probably require more coding.

    Not sure how you want yours to work. Your description is a bit vague. Does the player place a full predetermined path? Or can they adjust the path on the fly? Is there path finding involved? etc.
     
  31. tistik

    tistik

    Joined:
    Mar 15, 2012
    Posts:
    7
    There's nothing set in stone for now, but the idea would be that instead of having pre-built levels the players have to beat, they have their homeland they need to manage. So it's somehow a one-map game, where they can make paths for their "resource gatherer creeps" but regularly waves of invaders will attack and invaders can also follow those paths. So the player is torn between optimizing resource production and optimizing defence. Among references that inspired this idea are games like Mob Factory or Rift Breaker that are not pure TD games but add an interesting twist to the genre.

    Question: what would happen if each and every cell on the grid was walkable? Would the creeps still be able to find the best path? If so, the player would then have to decide where to place blocking structures and where not to depending on the (regularly-changing) resource locations and enemy spawn locations.
     
  32. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    It doesn't matter the whole grid is walkable or not, the pathfinding algorithm will always find the shortest path available. At the end of the day, it's about getting from point A to B. If you have a open grid without any obstacle, the creep will just cut through it in a straight line.
     
  33. tistik

    tistik

    Joined:
    Mar 15, 2012
    Posts:
    7
    Okay so I see a workaround to my first question here, correct me if I'm wrong: if the map is an entire open grid, then the player can make paths by adding blocker elements.
     
  34. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Correct.
     
    tistik likes this.
  35. Popcony

    Popcony

    Joined:
    Apr 14, 2014
    Posts:
    17
    I'm trying to implement a feature where platforms can be at arbitrary angles and towers can then be placed at an angle. I'm trying to make Simple Path and Branching path levels that the creeps can circumnavigate. The creeps move in this fashion because of the waypoints. I love that. But I'm trying to rotate the platforms around a cube in the center of the scene. When I try to rotate the platforms and press play, they snap back to being level. Then I change the rotation while it's running and try to place a tower. It snaps into place just fine, but the tower is level to the world, not the local rotation of the rotated platform. How do I resolve this? Preferably with little to no code modifications.
     
  36. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    You will need to modify the code unfortunately. The good news is you can get away with as few as 2 lines of code.

    First you need to remove line47 of of BuildPlatform.cs, in Format(). Which looks like this:
    thisT.eulerAngles=new Vector3(90, thisT.rotation.eulerAngles.y, 0);
    Then in UnitTower.cs, you need to add this in SetBuildPoint() after line 397:
    transform.rotation=platform.transform.rotation*Quaternion.Euler(-90, 0, 0);
    That should do it as far as I can tell.
     
  37. Riviere_N

    Riviere_N

    Joined:
    Jul 14, 2022
    Posts:
    9
    Hi Song, me again.

    Naive question: Are the Perks to be active on the scene immediately after purchase?
    I'm using perks to Modify effects and fro the life of me I can't get them to "manifest"
    ( if the effect by default slows a unit by 50%, after the perk is purchased the same effect now should slow the unit by 80%) but After the perk is purchase I can't seem to get it to "manifest" , only the default effect still playing. No matter if the perk is for a new tower, modified tower, etc.
    Is there a "refresh" somewhere? I'm concerned that as I've implemented a custom save mechanism, somewhere deep I've messed something...
    And "no" and don't have Perk as Game Scene upload_2024-4-2_19-52-59.png
     
  38. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Yes. They apply immediately after they are purchased. But you will need to enable the option 'Game Scene' though.

    Just to clarify. Disable game scene is for code optimization purpose when you have Perk Manager running in your main menu or in a none game scene. So when you purchase a perk, it doesn't have to run the whole logic of updating the game.
     
  39. Riviere_N

    Riviere_N

    Joined:
    Jul 14, 2022
    Posts:
    9
    A ha!.. I had interpreted "Game Scene" exactly the opposite way. thanks a million and sorry!
     
  40. shiguresasebo

    shiguresasebo

    Joined:
    Sep 22, 2023
    Posts:
    1
    Hi, I'm trying to create a ground effect that deals damage over time to any enemy that steps on that effect.

    You can think of it as something like this. When the cannon tower shoots an enemy, it will spawn an aoe area right under that enemy and deals damage or slow down,... any enemy steps on the aoe area.

    But I'm getting stuck at trying to create that effect using TDTK4. I did add the effect to the cannon tower, but all it did was cast the effect on the enemy that was hit, not the other enemy that pass through the area.

    Is there a way to make this effect possible using the current TDTK4?

    Edit: I'm having a new problem that I don't know if it is a bug or not

    If a unit walks over a mine that only casts effect on them, both the mine and effect deal 0 damage, there is a grey hp bar on the enemy. I expect it will be either full white hp bar or just no hp bar at all. So I'm reporting this back to you, sorry if it is intentional

     

    Attached Files:

    • bug.png
      bug.png
      File size:
      25.3 KB
      Views:
      3
    Last edited: Apr 6, 2024
  41. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Unfortunately the effect can only be applied on a unit, either a creep or a tower. To create a ground effect like that, you will have to do some custom scripting. It's very simple. Something like this will do:

    Code (csharp):
    1.  
    2. using TDTK;
    3.  
    4. public class Custom_AOEDOT : MonoBehaviour
    5. {
    6.     public float range=3;
    7.     public int duration=5;
    8.    
    9.     public float damage=1;    //damage per seconds
    10.    
    11.     IEnumerator Start(){
    12.         while(duration>0){
    13.             List<Unit> tgtList=SpawnManager.GetUnitsWithinRange(transform.position, range);
    14.            
    15.             for(int i=0; i<tgtList.Count; i++){
    16.                 tgtList[i].ApplyAttack(new AttackInfo(damage));
    17.             }
    18.            
    19.             duration-=1;
    20.            
    21.             yield return new WaitForSeconds(1);
    22.         }
    23.        
    24.         Destroy(gameObject);
    25.     }
    26. }
    27.  
    You can attached that script to a gameobject and set it as the hit effect of the cannon tower.
     
    shiguresasebo likes this.
  42. cj_jk

    cj_jk

    Joined:
    Feb 16, 2020
    Posts:
    2
    hello.

    PerkEditor's ModifyTower type Perk seems to affect not only Tower but also Creep.

    Is the only way to deal with this is to use different PrefabIds for Tower and Creep?
     
  43. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    That's one way to get around the problem. Or you can try the package I've just sent you. That contain the fix for the bug. Sorry for the trouble.
     
    cj_jk likes this.
  44. cj_jk

    cj_jk

    Joined:
    Feb 16, 2020
    Posts:
    2
    Thank you for your reply!

    I was able to confirm the fix in the package I received.

    I always cheer for you. Keep up the good work!