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.

TowerDefense ToolKit 4

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

  1. thefreik

    thefreik

    Joined:
    Sep 9, 2016
    Posts:
    3
    Hey Song!

    I've noticed that my towers and creep are shrinking and becoming weird everytime they respawn. I think it's because their values are not reset when they are pooled. But I've also noticed that this persists through restart. Certain gameobject keep shrinking between plays :S

    And some feedback from an artist-dev, just enable animations on everything even if you think it might be unnecessary :D Animations give so much life to a game, even if it's just a mine (you might want to animate it flying up in the air when it gets destroyed or something). Better to have the option to crank up the juice on everything :)
     
  2. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    For anyone using URP, here's the modified Custom Overlay shader code.
    Code (CSharp):
    1. Shader "Custom/BlendColorsOverlayTexture" {
    2.     Properties {
    3.         _Color1 ("Color1", Color) = (1,1,1,1)
    4.         _Color2 ("Color2", Color) = (0.5,0.5,0.5,1)
    5.         _MaskTex ("Mask (A)", 2D) = "white" {}
    6.         _MainTex ("Detail", 2D) = "white" {}
    7.         _Glossiness ("Smoothness", Range(0,1)) = 0.5
    8.         _Metallic ("Metallic", Range(0,1)) = 0.0
    9.     }
    10.     SubShader {
    11.         Tags { "RenderType"="Opaque" }
    12.         LOD 200
    13.  
    14.         Pass {
    15.             HLSLPROGRAM
    16.             #pragma vertex vert
    17.             #pragma fragment frag
    18.             #pragma target 3.0
    19.  
    20.             #include "UnityCG.cginc"
    21.  
    22.             struct appdata {
    23.                 float4 vertex : POSITION;
    24.                 float2 uv : TEXCOORD0;
    25.             };
    26.  
    27.             struct v2f {
    28.                 float2 uv : TEXCOORD0;
    29.                 UNITY_FOG_COORDS(1)
    30.                 float4 vertex : SV_POSITION;
    31.             };
    32.  
    33.             sampler2D _MainTex;
    34.             sampler2D _MaskTex;
    35.  
    36.             half _Glossiness;
    37.             half _Metallic;
    38.             fixed4 _Color1;
    39.             fixed4 _Color2;
    40.  
    41.             v2f vert (appdata v) {
    42.                 v2f o;
    43.                 o.vertex = UnityObjectToClipPos(v.vertex);
    44.                 o.uv = v.uv;
    45.                 UNITY_TRANSFER_FOG(o, o.vertex);
    46.                 return o;
    47.             }
    48.  
    49.             fixed4 frag (v2f i) : SV_Target {
    50.                 fixed alpha = tex2D(_MaskTex, i.uv).a;
    51.                 fixed3 color = lerp(_Color1.rgb, _Color2.rgb, alpha).rgb;
    52.                 fixed4 detail = tex2D(_MainTex, i.uv);
    53.                 color = lerp(color, detail.rgb, detail.a);
    54.                 fixed4 outputColor;
    55.                 outputColor.rgb = color;
    56.                 outputColor.a = 1;
    57.                 return outputColor;
    58.             }
    59.             ENDHLSL
    60.         }
    61.     }
    62.     FallBack "Diffuse"
    63. }
     
  3. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    Was just looking back through and if anyone's interested I updated the SlaveManager to be more of a Manager.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections.Generic;
    3.  
    4. [System.Serializable]
    5. public class TargetSlavePair
    6. {
    7.     public Transform target;
    8.     public Transform slave;
    9. }
    10.  
    11. [System.Serializable]
    12. public class TowerPair
    13. {
    14.     public string towerName;
    15.     public List<TargetSlavePair> targetSlavePairs = new List<TargetSlavePair>();
    16. }
    17.  
    18. public class SlaveManager : MonoBehaviour
    19. {
    20.     public List<TowerPair> towerPairs = new List<TowerPair>();
    21.  
    22.     void Update()
    23.     {
    24.         foreach (TowerPair towerPair in towerPairs)
    25.         {
    26.             string towerName = towerPair.towerName;
    27.             List<TargetSlavePair> targetSlavePairs = towerPair.targetSlavePairs;
    28.  
    29.             foreach (TargetSlavePair pair in targetSlavePairs)
    30.             {
    31.                 Transform target = pair.target;
    32.                 Transform slave = pair.slave;
    33.  
    34.                 slave.localRotation = target.localRotation;
    35.             }
    36.         }
    37.     }
    38. }
     
  4. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    To be honest, I didn't find where to do it in your script
     
  5. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    I think this is what he's talking about:
    Code (CSharp):
    1. float angle=Vector3.Angle(dir1, dir2);
    2.            
    3.             return new Vector3(-dir.z, 0, dir.x)*pathOffset*(1+Mathf.Min(1, (angle/90f))*.4142f);
     
  6. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    upload_2023-5-29_1-49-40.png

    I've already changed it here, but to be honest I didn't notice any changes
     
  7. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    How can I bind the rotation of the tower sprite, for example, where does the tower shoot? what is responsible for this in your script?

    upload_2023-6-1_4-2-51.png
     
    Last edited: Jun 1, 2023
  8. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
     

    Attached Files:

  9. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    Search Unit.cs for targetingFOV
     

    Attached Files:

  10. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    I have a 2d game, exactly should I look for it?
     
  11. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    Didn't realize this is compatible for use with 2D
     
  12. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    Sorry for the stupid question, but why does the SFX slider reduce all sound? how to make the sounds of construction and shots be separate, and the music separately?

    upload_2023-6-13_1-32-43.png
     
  13. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    upload_2023-6-17_3-17-58.png

    it seems to have indicated a cap of 100, but resources are still accumulating why so?
     
  14. ozziechan

    ozziechan

    Joined:
    May 13, 2020
    Posts:
    1
    Some progress......


    I have creeps replaced (not in the video linked) and this weekend I'll be replacing towers.... I look forward to the struggles lol.

    Thank's @Song_Tan -Wonderful asset for a noob like myself. Allows me to create stuff I wouldn't have thought possible with limited resources/solo/skillset, and it's appreciated.

    1 quick question- Is there any quick way built in to the template that would allow me to show the resources gained when a unit is destroyed in the same way that damage is currently displayed over the unit? Or would that be something custom?

    Thanks.
     
    toddkc likes this.
  15. BellokTV

    BellokTV

    Joined:
    Dec 14, 2018
    Posts:
    17
    my turret pivot assignments keep getting reset randomly even when I am not working on the specific tower that gets reset. This is extremely aggravating as the tower turrets will randomly stop targetting things or fail to rotate until I reset the setting manually... I keep having to reset them over and over... please fix it as I have not changed any code at all and the only other assets imported are the tower prefabs I am using.

    It also resets if you make any changes to stuff like the icon. That is also annoying, but just a QOL thing. If we haven't changed the prefab assigned, then the rest should stay the same...

    Here's a video reproducing the issue.
     
    Last edited: Jun 26, 2023
  16. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    Has the author abandoned support?
     
  17. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    On the forum it seems so.
     
  18. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    After this many years I cannot imagine they would just bail with no notice. They recently announced their game, Axon TD, probably just busy with that.
     
  19. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    upload_2023-8-30_20-32-1.png

    How do I add my own field to this editor?
     
  20. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,964
    Sorry for not responding folks. I missed a notification somewhere. Plus I'm extra busy than usual I forgot to do my regular check. I believe I've responded to some of the post here via email. Anyway...

    @darknside, the script in question is W_UnitTowerEditor.cs. To add your own field, you will have to modify that. Fair warning: this is going to be a bit difficult unless you are pretty comfortable with coding. You can find all the reference you need here: https://docs.unity3d.com/ScriptReference/EditorGUI.html. And a simple tutorial if you need it - https://learn.unity.com/tutorial/editor-scripting?uv=2018.1#.
     
    darknside likes this.
  21. sayedstafa

    sayedstafa

    Joined:
    Feb 21, 2014
    Posts:
    3
    @Song_Tan
    upload_2023-8-30_18-39-44.png
    I'm having an issue with some towers not being able to deploy.

    I copied the tower prefabs from TDTK/Prefabs/Towers and put the copies into my own folder so that I can make changes to the duplicates and keep the originals intact.

    I added the copies to the Tower Editor list, and two of the towers are no deploying. The Machine Gun and the Laser Tower. For some reason, those two towers are not deploying and I have been tinkering around with the settings to try to see why they wont deploy but I can't figure it out. They are literally just duplicates of the original prefabs. The other duplicates deploy fine and the originals deploy fine but I can't figure out these two. I would appreciate any help.
     
  22. darknside

    darknside

    Joined:
    May 4, 2021
    Posts:
    92
    Please tell me which piece of code is responsible for disabling enemies when they have reached the end point of the path when hp is taken away? I want to connect animation there
     
  23. chun1617

    chun1617

    Joined:
    Sep 9, 2023
    Posts:
    1
    Hello Song, Can you screenshot about how to make creep animation?
    I tried to add Clip move animation in "Animation Setting" but it doesn't have anything happen.
     
  24. Niroan

    Niroan

    Joined:
    Jun 16, 2019
    Posts:
    114
    Is it possible to make a tower shoot piercing attack somehow?
     
  25. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,964
    You will have to elaborate what do you mean by piercing attack. It means different things in different game.
     
    Niroan likes this.
  26. Niroan

    Niroan

    Joined:
    Jun 16, 2019
    Posts:
    114
    Hi Song

    By piercing i mean bullets flying trough the enemy. So if it had piercing 2 Then it would hit 2 enemies before it exploded or Got Removed. And so on.

    Like hitting in a Line Then depending on How much piercing your Towers have it could hit more and more enemies. Would be a Nice gane mechanic for Any td game.

    i have chain attack where they jump depending on skills but not This.
     
  27. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,964
    Not without code modification I'm afraid. The way shoot-object works in TDTK is each shoot-object is fixed on a target. When they hit, they just hit on the target. The piercing that you refer to frankly require another kind of implementation, where a trajectory is determined and then a check is perform to see how many target is hit along the way.
     
    Niroan likes this.
  28. Niroan

    Niroan

    Joined:
    Jun 16, 2019
    Posts:
    114
    Yeah, Your right. I think we can use AOE radius to act the same way sort of, if we control it correctly.
    Btw. Congrats on your new game, looks fun. Watched a youtuber play it hehe.
     
  29. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,964
    Thank you!
     
  30. Riviere_N

    Riviere_N

    Joined:
    Jul 14, 2022
    Posts:
    2
    Hi Song Tan and team,

    I just finished some customisation of the TDTK package:

    Added a custom save

    Modified the powers to have some work as Abilities while others are to be built-in platforms

    I’ve created an infantry-type tower with sentries that patrol the tower on the lookout for creeps, etc.

    My question is related to animations: The manual says to replace any of my FBX/Prefabs ‘animation controllers’ with the Controller included in TDTK (TDUnitController).

    But animations are wrecking my brain.

    So far, I can't get consistent results.

    A) Some of my custom tower animations & controllers work correctly, without ever using the default controller.

    B) Some of the animations don’t regardless if:

    a. I use my custom controller with custom animations and the animations listed in the towerEditor, nor if

    b. I use the default controller with custom animations and the animations listed in the towerEditor, nor if

    c. I use the default controller and only declare the custom animations in the tower editor.

    What is the method TDTK is expecting the animations to be structured?
     
  31. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,964
    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.
  32. Riviere_N

    Riviere_N

    Joined:
    Jul 14, 2022
    Posts:
    2
    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!
     
  33. 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
  34. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,964
    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.
     
  35. 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
  36. Niroan

    Niroan

    Joined:
    Jun 16, 2019
    Posts:
    114
    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.
     
  37. Song_Tan

    Song_Tan

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