Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

TowerDefense ToolKit 4

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

  1. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,638
    I'm extremely sorry for going missing on this thread. For some reason I've stop receiving notification about new post starting May. I'll try to answer all the question I've missed. Please re-post again if I've missed them. Just a note in the future, please email me and let me know if I didnt respond to your post. Normally it doesn't take more than a few hours, a day or two in extreme cases for me to respond.

    I think what you mean is the path-smoothing? I can expose an option in the PathFinder component so that you can turn the feature on and off. I'll do that in the next update. Please send me an email if you want to get it in advance.


    No worries, I'm happy to answer them. First question, yes the creep can be set to attack tower. They can even be set to take pot-shot at tower as they go past, or even stop entirely to engage when they encounter a tower (a la Plant vs Zombie).. Second question, unfortunately you can't do that.


    It works fine with 2D asset to a certain extent. You may need to do some slight modification here and there depends on the 2D asset you are going to use.


    There's no such function yet. You can add this (it's very simple):
    Code (csharp):
    1.  
    2.     public static void GameOver(){
    3.        instance.gameState=_GameState.Over;
    4.        if(onGameOverE!=null) onGameOverE(false);
    5.      }

    I take it you mean to do a shoot animation when attacking? Yes, please check the example tower prefab under folder "TDTK/Animation/Tower".


    Can you please be more specific in what stopping you from doing that? Is there an error? Or the change reset itself?


    @Chaz32621, @Warlord4, To avoid input confusion which duplicate input in certain circumstances (Unity will emulate mouse as touch input and vice-versa), I've disabled mouse input when build platform is set to mobile(iOS, Android, etc). So if you have your target build platform set to mobile, you will need to test it using UnityRemote. So please keep in mind about this.


    Once again, I'm extremely sorry for the late respond.
     
    Last edited: Jun 29, 2015
    MrGky93 likes this.
  2. SoRobby

    SoRobby

    Joined:
    May 1, 2015
    Posts:
    2
    Is there any way in the next update, you can create a menu, save, and level selector system? I am a professional 3d Artist and have little programming experience unfortunate. So would it be possible to add that in a future update or direct me somewhere to utilize these systems?
     
  3. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,638
    I'm afraid I'm not going to do that for several reasons. First it's out of the scope of the toolkit. I rather focus on TD or gameplay aspect of the kit. Furthermore, these system are often highly specific to each project. It's possible of course, to make a generic solution typically seen on mobile app. But frankly I'm quite against the idea that of doing that.

    There are some 3rd party package that do what you need (menu, level select, level progression saving, etc.). My impression is there are pretty user friendly. Perhaps you can check those out.

    However if you insist, I could do it for you as a paid job. They will be exclusive to you and you'll have a greater degree of customization available. Obviously that would cost a lot more.
     
  4. Warlord4

    Warlord4

    Joined:
    Nov 26, 2012
    Posts:
    14
    Hello, can't understand what is not right here. I am trying to make my creep attack tower but the creep only fly along the tower. And i have such mistake!
    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. TDTK.Unit.ScanForTarget () (at Assets/TDTK/Scripts/Unit.cs:328)
    3. TDTK.Unit+<ScanForTargetRoutine>c__Iterator5B.MoveNext () (at Assets/TDTK/Scripts/Unit.cs:294)
    43tr f.png Безымянный.png
     
  5. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,638
    Looks to me that the problem is not with the editor setting but you have a other collider in the scene which is assigned to layer Unit or UnitF (30 or 31). My guess is you have more than 1 collider on the tower (extra on the child object maybe) and the whole tower hierarchy is assigned with the layer Tower. Hence the extra collider is mistaken as a target.

    Make sure you have no unnecessary collider in the scene as well as on the prefab. If you must have them, make sure they are assigned with the correct layer (default or other if they are not related to TDTK)
     
  6. Warlord4

    Warlord4

    Joined:
    Nov 26, 2012
    Posts:
    14
    Thank you very much, there was two coliders in my tower hierarchy! Now everything works fine!
     
  7. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,638
    No problem. :)
     
  8. Warlord4

    Warlord4

    Joined:
    Nov 26, 2012
    Posts:
    14
    Hi again. Can you help with one question? I can't understand no how to call variable from UnitCreep! (The type or namespace name `UnitCreep' could not be found. Are you missing a using directive or an assembly reference?)

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Shield : MonoBehaviour {
    5.  
    6.     public UnitCreep unitCreep;
    7.     public float fullShield1 = unitCreep.fullShield;
    8.     public GameObject Effect;
    9.  
    10.     void Awake(){
    11.         unitCreep=this.gameObject.GetComponent<UnitCreep>();
    12.     }
    13. }
     
  9. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,638
    You simply need to add using TDTK in the top of your code. Like so:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. using TDTK;    //add this
    5.  
    6. public class Shield : MonoBehaviour {
    7.  
    8.     public UnitCreep unitCreep;
    9.     public float fullShield1 = unitCreep.fullShield;
    10.     public GameObject Effect;
    11.  
    12.     void Awake(){
    13.         unitCreep=this.gameObject.GetComponent<UnitCreep>();
    14.     }
    15. }
     
  10. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    108
    Hello, I'm wondering about getting this type of turret working in my game: http://cdn.shazoo.ru/8617_59UUEMA5Ga_ih_missileturret01.jpg Basically, the base stays stationary, the turret and arms rotate on Y, but only the turret rotates on X. I've tried attaching the arms to the turret, and they rotate on the Y with the turret, but also rotate on X... Look forward to seeing how to go about this, thanks!

    *edit - I know I can disable the turret rotate on X, but I would like that to be part of the movement for realism... thanks :)
     
    Last edited: Jul 19, 2015
  11. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    108
    Ok, I figured it out. Please let me know if this is the best way... I created 3 separate groups (base, arms, barrel) and placed them in the Unit Tower Script on my prefab as pictured and it's working great. I do have another few questions though, what is "This T" used for & how to I disable to "delay" for when my turret fires then turns quickly (I can visually see the barrel unlocking from the arms and then snap back? Thanks.
     

    Attached Files:

    Last edited: Jul 19, 2015
  12. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,638
    As far as I can tell, there's only one way to do it. So if it's working, it's working. :)

    Actually there are two example tower prefabs in the package that use this sort of rotation model, namely mg-tower and artillery-tower. You can refer to that as an example. You have probably work this out, it's all about having the right hierarchy setup and assign the correct child objects as the TurretObject and BarrelObject.
     
  13. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    108
    My animations are working, but I had to change my prefabs Hierarchy while they were marked as Legacy, then switch to Generic in order to get the Avatar to use with the TowerAnimatorControllerTemplate. I was able to do this with single barrel turrets, but am now having issues while try to do the multiple barrel turrets. Also, while running the game, I'm getting Console warnings saying to change the animations to legacy, even though they are working correctly. I'm wondering if someone might be able to do a short walk through video on how to animate a few different turrets using Legacy animations. Any help would be appreciated, thanks.
     
  14. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    108
    Ok... I figured out the double barrel, but really do need to figure out the animation issues please. For a Tower Prefab that has an animation attached, do I only need the animation to be placed on the Parent object, the one with the UnitTower script or does it need to be on only the original animated prefab? I have it placed on the main parent with the script as well as the original prefab that makes up the gun itself, so this is probably redundant...
     
    Last edited: Jul 20, 2015
  15. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,638
    It depends on the animation and how the tower is animated. A tank that need to traces its target with a turret while it's base stay still will certainly have a different setup compare to a archer character that rotates it's whole body to face the target. The rule of thumb is you will need just one Animator component on the prefab. But in which object it should be attached to are depends on the setup. Typically this needs to be on the default animated object, not the root object. Then on the root object itself (the one with UnitTower component), you add a UnitTowerAnimation component where the Animator can be assigned to. This UnitTowerAnimation is the component responsible to control the Animator component.

    So yes, from what you have described, seems like you have an extra Animator that is redundant.

    Hope this make sense.
     
  16. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    108
    Yes makes sense, and now I know proper terminology for root object :)
     
  17. Gorgoth

    Gorgoth

    Joined:
    Jul 20, 2015
    Posts:
    8
    Hi, i wonder how can I keep my ground creeps on the ground? They are, depending on the path, hovering a little above the ground. Or is it possible to let the path following the ground? If i use rigid bodys for the creeps they stay on the ground but then there are problems with pathfinding or path navigation as they try to reach a waypoint, even if it is a bit above them and get stuck or they jump a bit between two locations. Any suggestions what to do? Thanks.
     
  18. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,638
    I wouldn't recommend you to use rigidbody with gravity under any circumstances. Unless you know exactly what you are doing and capable of editing the code to make it work. The default code simply will not work well with rigidbody with gravity.

    The y-axis position of the creep will always stick exactly to the y-axis position of the path. So to make it look as if they are walking/moving on the ground, you first need to make sure the bottom end of the creep's mesh is at it's root object y-axis position. Then you will need to match the y-axis position of path to the ground.

    Please refer to the image below. All the y-axis position of the creep, path, and ground are at 0. The y-axis position of the creep's mesh (skeleton_mecanim) are adjusted so that the bottom end of the mesh is at the y-axis position of it's root-object (Creep_Skeleton_Mecanim).

     
  19. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    108
    On the turret prefab, is there a public field to apply the max X rotation degrees downward? When a Creep gets close the turret rotates down into itself... I would like the turret to only rotate X degrees downward if possible. Tried changing the Dir Scan Angle & Dir Scan FOV, but nothing changes. Also wondering about Scan Dir T, not sure what object could be placed in that field, can you also give a short description of these public fields?
     
    Last edited: Jul 20, 2015
  20. jinudave

    jinudave

    Joined:
    May 25, 2015
    Posts:
    1
    Hi songtan,

    I just bought your toolkit and it's been fantastic. I've been experimenting with it since!

    My goal is to create a game like Kingdom Rush and I scrubbed this forum to find any hints on how to accomplish this. I came across this quote. Though I understand the complexities that can arise from modifying a toolkit to accommodate this, is there any place I can start?

    I've been able to work in a third-person controller and get the mouse and camera to react properly. How does damage work in the toolkit? I tried to create a "hero" class that derives from the UnitTower.cs and make it less like a tower but that didn't work so well.

    Thanks again,
    -jinudave
     
  21. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,638
    @LoveTheVape, Unfortunately there's no limit to the x-axis rotation of the turret. This is inherently due to there's no x-axis fov limitation when targeting. Both DirScanAngle & DirScanFOV are only used for tower which target a specific direction. They can be used to limit the turret rotation in x-axis but then it would limit it's targeting area to a specific conical area in y-axis. Finally if a field doesn't not shows up in TowerEditor, they are used internally by the script. You will never need to be concern about them.

    I would suggest you to try design around the issue. If the tower targets only ground unit, you can get around it by either lowering the height of the tower, or increase the spacing between the towers and the path. For anti-air tower, you will have to have the tower designed in a way that the turret can rotate all the way in x-axis.


    @jinudave, Thanks for your purchase and glad you like the toolkit. I'm afraid "Is there any place I can start?" is too generic a question for me to answer really. It depends on how exactly you want your game to be and what are the features you are missing at the moment as well as how comfortable you are to work on each particular feature. Basically it's more to do with project management. Not knowing anything about the project, I'm probably not the best man to answer that.

    But to address the quote, it would be considerably easy for you to modify the kit then for me to extend it. Understand this, when I try to extend the toolkit by adding new feature, not only I have to make sure they work, I'll also have to take into consideration that they should be as flexible as possible for customization. Much like the stuff you see in the current toolkit. For instance you can easily configure how the tower behave, how effective they are, etc. For user like you however, you would have a very specific design you want to achieve therefore it's a lot more straight forward.

    As for how damage works, you can learn about how damage works in TDTK_Class_AttackInstance.cs. Basically everytime an attack is initiated, an instance of AttackInstance is created. The instance then calculated the hit chance, damage, critical, etc. of that particular attack using stats from the both unit involved. You can find out more looking at TurretRoutine() (where an attack is launched) and ApplyEffect() (the function called when a unit is hit) in Unit.cs. Hope this help. Let me know if you have any other question.
     
    Last edited: Jul 21, 2015
  22. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    108
    Thank you for the suggestion, I will design around.
     
  23. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    108
    Song, I'm seeing that the Build Duration adjusts how long it takes to build a tower, but the tower appears during that duration. Would it be difficult to add tick box that gives you the option for a tower to appear right away or only appear when the delay has finished? I too am not that great with animations yet, so I think this could be very helpful in getting an animated Building Effect working easier. For my situation, all I would need to do is tick the box to hide the tower until the duration has timed out, then the tower will appear in place of the dummy turret that I raised up from the ground and then destroyed at same time as duration timeout. Thanks :)
     
  24. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,638
    You can't do that. But you do have a fair point so I've just add that. Please send me an email so I can send you the mod.
     
  25. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    108
    Email sent, thank you sir.

    *Update - It works perfect, thanks!
     
    Last edited: Jul 21, 2015
  26. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    108
    Last edited: Jul 22, 2015
  27. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,638
    That is really cool!!
     
  28. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    108
    So this is all based on a flat plain, but you can have them at different Y heights and they still work... Would it be very difficult to make this work with a spherical world? I'm thinking something along the lines of this:
     
    Last edited: Jul 23, 2015
  29. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    108
    Curved World is using shaders to make everything look rounded I believe. So you can still build on a flat plain, but when it's rounded, all the other mechanics need to translate accordingly I suppose. Anyone tested TDTK with Curved World with success?
     
  30. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,638
    Well I never tested TDTK with Curved-World. From the description, it's just a camera warping algorithm to make the world look bended or curved. So in theory you don't need to alter the existing mechanic at all. But I suppose it best to ask the developer if that's the case.
     
  31. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    108
    Hey Song, I'm making progress on tweaking this asset for VR, but I'm stuck on an issue. I have all of the canvas in 3D space & working with a racycast instead of the mouse cursor. But this isn't working with the Platforms. Can you please steer me in the right direction to be able to use the raycast instead of the mouse cursor on the platforms?

    *Edit - Here is the script I'm using along with a basic form of the script. Please reference if needed, thanks. Advanced - https://goo.gl/p97agu Basic - https://goo.gl/pPZyFj
     
    Last edited: Jul 26, 2015
  32. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    108
    Also, would it be really difficult to make it so the platforms can be rotated in any direction and still be able to be built on accordingly? Example: Right now the platforms exist parallel to the X axis ("flat" on the ground) I would like to rotate it 45 degrees on the X axis and have the tower build accordingly so it would be sitting on the ground @ a 45 degree angle. Thanks.
     
  33. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,638
    Took a look at your code. I notice you are using eventSystem.RaycastAll. For your information that only works with UI element. It wouldn't work with non-gui object. For that you will need to use Physics.Raycast. Something like this:
    Code (csharp):
    1.  
    2.     //pointer being the cursor position
    3.      void DetectPlatform(Vector3 pointer){
    4.        LayerMask maskPlatform=1<<LayerManager.LayerPlatform();
    5.      
    6.        Ray ray = Camera.main.ScreenPointToRay(pointer);
    7.        RaycastHit hit;
    8.        if(Physics.Raycast(ray, out hit, maskPlatform)){
    9.          Debug.Log("platform detected - "+hit.transform);
    10.        }
    11.      }
    12.  
    You can tilt the platform anyway you like if you remove line131 in FormatPlatform() in BuildManager.cs (which goes like this: platformT.eulerAngles=new Vector3(0, platformT.rotation.eulerAngles.y, 0)). A warning though, you will be doing so at your own risk. :)
     
  34. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    108
    Thank you for your response, really appreciate your help on this.
     
  35. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    108
    Song, I have everything in place with the raycasting, but I still need the mouse cursor hovering over a platform to be able to build on it. I would like to only use a 360 controller to play the game. I know all of the 360 controller commands, but not sure how to implement this into TDTK. Right now I have a raycast coming from the camera, colliding with the platforms and activating the TileIndicator_Cursor. From here I would like to simply press "360_AButton" and bring up the build options. Can you please let me know best route for this? Thanks!

    *Edit - I will not be using Drag&Drop feature!
     
    Last edited: Jul 27, 2015
  36. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,638
    The key thing here is BuildManager.CheckBuildPoint(). Which is used to setup a potential build position on a platform. Like BuildManager.SetIndicator(), it uses the cursor position to determine the build-tile on the platform. So you need to modify CheckBuildPoint() to use the same raycast method you use are using to determine the build position. Next is to get an input from the controller. By default, the UI uses mouse input so it's something like if(Input.GetMouseButtonDown(0)). You just need to change the input condition to detect the controller button you want. It's not so different from mouse input, only that you might want to configure the input in ProjectSetting/Input and have your code to match your setting.

    The logic (based on existing one in UI) is still similar, detect a button press, call BuildManager.CheckBuildPoint() to determine the build point and check if a tower can be build. If yes, show the build menu.
     
  37. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    108
    Very good, thank you for the quick response!
     
  38. behnke101

    behnke101

    Joined:
    Apr 19, 2013
    Posts:
    4
    Song, The TDTK is amazing. I see it has been around for a while and has evolved heavily. Great work! $60 was well worth it. I am having an issue though. When I create any of the demo scenes as an .apk for android the GUI doesn't show up. Is this a know issue or may I be doing something wrong?
     
  39. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,638
    Thanks for your kind word.

    Which of the demo scenes you are using? There are two sets of the demo scenes. One are specifically set for mobile. The GUI is reason why there needs to be two sets of them (I might have explained about this in the documentation).

    At any rate, it sure sound like something has went wrong if the GUI doesn't show up at at all. Unfortunately I'm out of office for the day. I'll look into it you when I'm back this evening. Hope you understanding. In the mean time, any additional information you can give me might prove useful.
     
    behnke101 likes this.
  40. behnke101

    behnke101

    Joined:
    Apr 19, 2013
    Posts:
    4
    Thanks for the fast response. I now see there are two sets. Sorry. I ported out the mobile and it looks like that works. What's the reasoning for the two types (mobile vs PC)? The scene I ported has the drag and drop feature. Is this what is needed for mobile vs the clicking on a square and picking a type?
     
  41. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,638
    The only difference between those two set of scenes are the scaling of size of the UI component. Mobile device typically has a much higer DPI compared to pc and laptop (due to their higher resolution, small physic size). For that reason, the UI by default is going to look extremely small on mobile device without any adjustment. For those mobile scenes, I've used CanvasScalar on each of the Canvas object to scale it up by 2.

    Build-mode shouldn't affect any of this. Both PointNBuild and DragNDrop mode works on mobile.
     
  42. Popcony

    Popcony

    Joined:
    Apr 14, 2014
    Posts:
    14
    How do I integrate the TDTK with Mad Level Manager?
     
  43. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,638
    Dont think I'll be much help in this case. I figure most of the work/setup will be done using on MadLevelManager's end. However I'm not familiar with that at all.

    As far as I can tell, the only bit that concern TDTK is to register when the level is completed. For that you can add the MadLevelManager's API call in function _GameWon() in GameControl.cs. Fyi, _GameWon() is called everytime a level is completed.

    From what I can gather, those API should look something like this:

    string thisLevel=MadLevel.currentLevelName;
    MadLevelProfile.SetCompleted(thisLevel, true);
     
  44. Popcony

    Popcony

    Joined:
    Apr 14, 2014
    Posts:
    14
    My other question, this may be easier for you to answer, in the native TDTK pause menu, how does one change the "main menu" points to.

    In other words, in the native TDTK when you press the pause button, there are 3 options, "resume", "options", "main menu". How do I re-map what scene that button points to?
     
  45. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,638
    You can set those in GameControl, MainMenuName and NextSceneName respectively. However they are just for "main menu" and "next" button (only show up when the level is completed). Resume button obviously close the pause menu and option goes to option sub-menu so those two don't have any scene to load.
     
  46. roch13boy131

    roch13boy131

    Joined:
    Sep 14, 2013
    Posts:
    11
    Hey Songtan

    I have recently downloaded the free version of the tower defence kit on the Unity Assets store and i cant seem to upgrade my own personal tower(i can upgrade the stats but cant upgrade the appearance of it)

    Thankyou in Advance
    Kind Regards
     
  47. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,638
    I'm afraid that is not supported in the free version. You can only do that in the full version.
     
  48. roch13boy131

    roch13boy131

    Joined:
    Sep 14, 2013
    Posts:
    11
    Hey Song

    I just purchased your Kit so i can use the upgraded tower thing but there is a problem i can build in point and click only the towers that you provided but whenever i try to build my custom tower it shuts unity down, and drag and drop doesnt work at all

    Kind Regards

    Edit: I figured out why drag and drop wasnt working
    But now i just cant place my towers i can only place the ones that are in the kit
     
    Last edited: Aug 13, 2015
  49. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,638
    In what way you can place your tower? Can you open the build menu at all? Or it crash when you press the build button. Since the default prefab works, I can only assume the problem is the way you setup your own prefab. Have you follow the instruction in the documentation? Have you got any custom script on the tower prefab?
     
  50. roch13boy131

    roch13boy131

    Joined:
    Sep 14, 2013
    Posts:
    11
    i can click on the tower in drag and drop and drag it to the platform but once i try and place it it crashs unity aswell as pointandbuild i can click the platform and then when i click my custom tower it crashes i did follow all of the instructions and also kept it close to the MG Tower but it doesnt want to work

    and no no custom scripts on the tower
     
unityunity