Search Unity

TowerDefense ToolKit 4

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

  1. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    Awesome thank you!
     
  2. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    Hey Song, at runtime, in VR (6dof camera movement) if I select one of the perk abilities and look around, I see the red ring indicator moving around but it's apporox 90 degrees offset of the camera and I have to look down to line it up somewhat where I want it. I'm wondering if maybe there's some offsets in the coding or something?
     
  3. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I don't quite understand your question (surely you mean ability, not perk ability). The default indicator are setup to be on a fix rotation, that is aligned with horizontal plane. It's a prefab, assigned in AbilityManager, TargetSelectIndicator. So if you want to change the rotation, simply do it on the prefab. If you want to change the positioning or the rotation of the indicator during runtime, the code is in AbilityManager Update().
     
  4. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    Yes, sorry, I meant Ability. Got it, thanks!
     
  5. Jon_Brant

    Jon_Brant

    Joined:
    Mar 22, 2018
    Posts:
    56
    Hey Song, I'm having those crashing issues again I mentioned a page ago. I managed to catch this error before it closed on me: https://prnt.sc/pjv8z6, saw another one about Preview scenes but didn't catch it. I've attached a zip of my crash logs

    Also two more issues: 1) I'm getting a HUGE lag spike when I click to build my first tower of a game. ~5seconds or so it just freezes. I think it's filling the object pools maybe? If that's the case, can I make it do that in start somewhere?
    2) My creeps are SUPER jittery. Here's a video:
    I've tried turning off Snap to Direction, but that makes them spin in circles around the waypoints pretty often. Any ideas?

    Thanks
     

    Attached Files:

  6. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I believe I've fixed the editor crashing issue. From the crash log it seem like you are still using the old version. Try update your project. It should at least fix that.

    The freezing you experience when building your first tower has nothing to do with ObjectPoolManager. It doesn't prepopulate the pool. I suspect it's more to do with the loading of the asset on your tower (mesh, texture or animation perhaps). Try place a tower in your scene before playing and if that makes any difference.

    Finally about the creep spinning in circle, I can't replicate that. Can you give me the setting you are using? Specifically your creep speed and rotate speed.
     
  7. Jon_Brant

    Jon_Brant

    Joined:
    Mar 22, 2018
    Posts:
    56
    Oh crap, I thought I updated. Least that's an easy fix. For the freezing, that makes sense. It doesn't do it all the time, so I'll have to leave some prefabs in scene to make sure.
    For the spinning part, here's a screenshot of the settings: https://prnt.sc/pjz61k and here's a video:


    I tried to open up the creep settings window, to scroll to settings but it didn't record it. Probably because it's a pop up window. Screenshot shows the info though
     
  8. Jon_Brant

    Jon_Brant

    Joined:
    Mar 22, 2018
    Posts:
    56
    I think I narrowed it down, it seems to be to do with the creep's prefab's size. Here's another video:


    Both creeps have the same movement settings, one is just bigger. I can get it to stop by making the bigger one smaller, but I really want bigger sizes
     
  9. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Try switch of the 'Apply Root Motion' option in your creep animator. With that on, the movement range on your animation will be applied to your transform. I suspect that's what causing the creep to overshoot their intended waypoint. Hence they are flipping back and forth.
     
  10. Jon_Brant

    Jon_Brant

    Joined:
    Mar 22, 2018
    Posts:
    56
    They won't move without that turned on. I assumed that was normal, I guess it's not?
     
  11. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    It's an option, depends on if you want the animation to drive the model movement. This is useful for action game but not in our case where precise waypoint tracking is needed.

    You will have to rearrange your prefab hierarchy. Instead of having the UnitCreep script on the model prefab, you can create an empty game-object and place the model as the child object. The UnitCreep goes on the empty game object. Now the UnitCreep script can control the movement without interference from the animation.

    You can refer to the default example creep to see how this is done.
     
  12. Jon_Brant

    Jon_Brant

    Joined:
    Mar 22, 2018
    Posts:
    56
    Oh ok, that makes sense. I thought the UnitCreep was driving the movement the whole time, I guess it was just rotating them in the right direction with the animation doing the moving. Sucks to hear, I have about 50 prefabs to edit now lol. Thanks for the help though

    Edit: Also, I'm working on beam towers at the moment. I'm having an issue where the beam animation keeps playing if the creep move out of range of the tower, even when the tower is firing on a new enemy. This results in many copies of the beam being created, with only one aimed at the correct enemy.

    Is there a way to check if the turret is in range from ShootObject.cs? I have a reference to the target, but not the tower. If I could just check the range in there, I'd be fine
     
  13. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm not sure what exactly are you referring to. Is this your custom beam animation or your are just using the beam type shoot-object? Does the default shoot-object gives you any problem?
     
  14. Jon_Brant

    Jon_Brant

    Joined:
    Mar 22, 2018
    Posts:
    56
    Edit: Figured it out, I can just use GetComponentInParent at InitShoot. Thanks anyway, will leave in case it helps someone else
    Oh, sorry. Yes I'm using my own custom beam. I used the beam code as a base. Basically I want a continuous beam, so I just set the beam duration to like 5 seconds. That works for keeping the beam on, but when the tower's current target moves out of range, the beam keeps firing and the tower aims at a new enemy, firing and making another beam.

    I have no way of checking in the ShootObject that I can see. I can check the distance from the tower to the unit if I have a reference to the tower, but I'm not seeing one. I feel like I'm missing it somewhere. Do I need to get my own?




    Also the restructuring fixed the issue with jittery/spinning creeps. Thanks again
     
    Last edited: Oct 16, 2019
  15. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    I'm trying to figure out how difficult it would be to use a [character] as a tower. Basically, I want to be able to place [character] at specified [build point] locations and be able to control [him/her] upon build completion. I would like to be able to damage and take damage from other creeps, even if just mele. Think: [TDS character] - gives and takes damage from creeps, can be upgraded or sold, same upgrades as tower (+speed, +damage, +critical, etc...). Can you share any advice?
     
  16. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    As far as I can tell, everything you described there is readily available for a 'standard' tower. Except the term 'control' is a bit vague. How exactly do you control it, moving it using wasd key? manual attacking like a top down shooter?

    They key difference between TDSTK and TDTK is the targeting/hit mechanism and unit positioning. In TDTK, every attack has a target and is a guarantee hit. If you want a free from attack initiated and aimed by player, that have to change. You will need a detection mechanism (probably using collider) to detect if a shoot-object 'hit' anything in it's trajectory. As for positioning, as long as you don't need the player character to obstruct the creep, it's fairly straight forward. Simply use any movement control you want. You will still need to put some collider on the player character and the towers (even creep) if you don't want your character to simply 'ghost' pass everything.
     
  17. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    Yes, wasd type control. Thank you for the breakdown!
     
  18. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    Can you tell me how to remove the pause function from initiating when the Perk Menu is opened? I'd rather keep the pause functionality, but it's not important. I have the UI attached to the left controller and use the right controller to interact with it. When the game pauses it freezes the position the UI was paused at, so the UI needs to be lined right back up to that original position to function correctly.
     
  19. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Just disable the line Time.timeScale=0; (around line 190) in UIPerkScreen.cs will do the trick.
     
  20. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    Yes it did. Thanks.
     
  21. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    I've recently received and error. It doesn't affect anything that I've noticed... Any ideas?
     
  22. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Seems like you have an empty element in your CreepDB list. You can resolve it by manually 'clean' the list by removing the empty element. Just select TDTK/Resources/DB/CreepDB. Look at the component CreepDB and expand the list. If there's any empty element in the list, right click on it and remove it.
     
  23. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    That did it. Thanks again.
     
  24. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    I'd like to setup environmental damage to creeps. Example, creeps walk under bridge, player destructs bridge, bridge falls on creeps, creeps receive X damage. Can you please explain how to achieve this?
     
  25. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Something like this will do

    Code (csharp):
    1.  
    2. public Vector3 hitPosition;
    3. public float range;
    4. public float damage;
    5. public void TriggerEnvironmentDamage(){
    6.  List<Unit> tgtList=SpawnManager.GetUnitsWithinRange(hitPosition, range);
    7.  for(int i=0; i<tgtList.Count; i++){
    8.   tgtList[i].ApplyAttack(new AttackInfo(damage));
    9.  }
    10. }
    11.  
    Of course this is what you call when you want to damage the creeps. There are several ways to 'destroy the bridge' however and that is entirely up to you.
     
    Proto-G likes this.
  26. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    Perfect, that's what I was needed! No need to explain the bridge, that was just an example ;) Thanks so much!
     
  27. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    For this single tower, I would like to have the two archers rotate and fire independently from each other. I would also like to be able to set the Target Priority for each archer independent from each other. Is this already possible? If not, would it be difficult to implement?

    For reference, I know how to make a tower prefab. I'm just not sure what's the extent of the towers currently.

    Thank you.
     
    Last edited: Oct 27, 2019
  28. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Well I have to say this is not support by default. Unfortunately there's no easy solution to this due to the way the framework is designed..

    The tower scripts only assume each tower has only one turret. To do this without having to modify the tower script heavily, you have to run two instance of tower script on one tower prefab. The problem with this is the system assume you only ever have one instance of tower script on one tower prefab occupying one build spot. To get over these problem, the simplest way I can tell is to run a nested tower prefab (with it's on tower script and turret object) within a tower prefab.

    That leaves you with a problem with user interaction with the nested tower since the default UI (based on the default one tower on one built spot design) select the tower based on the build spot. So you have to somehow come out with a way to select the nested tower. I don't have an immediately solution for this honestly. You will probably have to ditch the default system and switch to a tower selection system based on clicking on the towers rather than the build spot.
     
    Proto-G likes this.
  29. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    Understood, thanks. I figured out a simple solution to adding multiple slave turrets with multiple barrel pivots.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. public class SlaveManager : MonoBehaviour
    4. {
    5.     public Transform target;
    6.     public Transform slave;
    7.  
    8.     void Update()
    9.     {
    10.     slave.localRotation = new Quaternion(target.localRotation.x,
    11.                                          target.localRotation.y,
    12.                                          target.localRotation.z,
    13.                                          target.localRotation.w);
    14.     }
    15. }
     
    MaxiMaximaal likes this.
  30. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    127
    Hey Song!
    I finally had time again to work on my game. Your previous suggestions were a great help and allowed me to add multiple animated objects with different animations to my towers and creeps and additional sound effects (among other things). So that really helped me a lot. For future versions of your excellent tool, I would love to see that as a built in option, if possible(PM me, if you need what I implemented for that, though I am sure you can do that way better than me). It would make it easier for me to keep up with future releases.
    I have another question for you: I would like to trigger an animation that will change the playing field in a way (e.g. a bridge collapses and that blocks a previously available path for the creeps. It should ideally be triggered by a new wave of creeps arriving. Do you have any suggestions for how to best implement that? Is there already some functionality/workaround for that, that I missed?
    Thanks!
     
  31. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    The best way to block/open-up new path is to make use of the existing system. You can use a script to place a dummy tower at a certain key build-point on the path to block the path, or the reverse to open up a path. The dummy tower is basically just an invisible tower that doesn't do anything but to block the path. Speaking of invisible, you will probably want to make the built-point invisible too. Then you can add what ever visual you want (like the bridge collapse in your example) to create the illusion. The only thing is you will need to do some light modification to prevent user from being able to interact with the said key build-point, or build/sell any tower on it.

    Hope this gives you some idea.
     
  32. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    127
    Thanks for the quick reply, as usual!
    I sort of get the idea. Question is, how do I trigger the event of the bridge collapsing when a certain wave appears?
     
  33. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    You can listen to TDTK.onNewWaveE event. Take a look at UIHUD.cs if you need an example.
     
  34. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    127
    Hey again!
    So I built my own solution, as it is a bit more flexible with a UI in the Spawn Manager.
    Things are working great. For now I have an object that I can move out of the way to increase the size of the playing field.
    All looks great, but... For some reason TDK won't let me build on the spot where the object was, even after it was moved out of the way. If I just deactivate the object before playing, it is fine, but even if I deactivate it mid game, the spot where it was remains inaccessible. I have a feeling that the creeps won't recognize it as gone either. Anything I can do to make that happen?
    Thanks again!
     
  35. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    127
    Never mind, I figured it out! Had to make the obstacle a Tower Layer, of course ;)
     
  36. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    127
    I take that back. It seems that I can now build on that obstacle, even if it is not gone...
    Hmmm. Song, do you have any ideas?
     
    Last edited: Nov 27, 2019
  37. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Well, the build platform setup it's individual 'node' when the game started. And it's not going do any update in runtime. If you have an obstacle in the way, it's going to think the 'node' is invalid.

    On the other hand, if a 'node' is available, you still can't build on it if there's an obstacle in the way (the code perform a check whenever you try to place a tower).

    So what I would suggest is start the game with the obstacles deactivated. Then use a script to activate them after short delay.
     
  38. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    127
    Thanks Song. So what layer type would I have to use for an obstacle that is there in the beginning of the level, but can disappear later? I am trying to understand that.
     
  39. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    'Obstacle' (layer26 by default) of course.
     
  40. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    127
    Thanks again. So I originally assumed that maybe the SpawnManager would be a good place to put the code for that, but now I am not so sure anymore. What do you think would be a good place to put the UI and code for (a) object(s) that are activated with a delay in TDK? I want to keep things somewhat universal.
    Is Game Control persistent over all scenes, or can I change values for each scene?
    Also, yet another stupid question, but what does the Object Pool Manager do?
     
  41. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    The best place would be your own script. Using the event system, you can avoid changing the original script entirely. But if you are going to modify the existing script, I don't see any difference between GameControl and SpawnManager. Both exist in every scene.

    Fyi, only static variables persist through scene.

    ObjectPoolManager recycle frequently used object that needs to be instantiated and destroyed by activate and deactivate them (Instantiate and destroy object is expensive). I wouldn't recommend you to tinker with it unless you know exactly what you are doing.
     
  42. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    127
    Sorry for being so needy. I managed to implement what you suggested. There is now a new entry in the Gamecontrols for an object that is activated later (for testing I did that in StartGame() though it is not exactly what I had in mind.
    Either way, my obstacle appears just fine after I initiate the first spawn. It is set to be an Obstacle Layer but that does not appear to be blocking anything. Neither towers nor creeps see it. If I set it to Layer Terrain, it correctly blocks my towers from being built, but the creeps still ignore it. It seems that no matter what Layer type I set it to, the creeps always ignore it.
    If it is there from the start, it successfully blocks everything, but it can not be removed later.
    Any ideas?
    I would think that ideally, I would be able to place this as prebuilt towers that I can remove later via TowerManager.RemoveTower(). But I am not sure how to best go about having towers built already when the game starts. I wished, I could just set the thing as being a tower layer type and then remove it later. But it looks like it is completely ignored by the game if it is not placed by the TowerManager.
     
    Last edited: Nov 28, 2019
  43. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Sorry my bad. I just discovered that the layer 'obstacle' doesn't quite work. But using 'terrain' should work just fine.

    Well it seems you misunderstood my suggestion in earlier post. You need to place down the obstacle at the start of the game but at a deactivate state. This would allow the platform to generate the build point at the start of the game so you can build tower. Then during runtime, if you want the build point to be blocked, activate the obstacle, deactivate it again to make it available.

    Also, creep path is setup during the start of the game. The only way to change it (block it) during runtime is to build a tower on the platform.
     
  44. andreigrigore

    andreigrigore

    Joined:
    Jan 23, 2016
    Posts:
    3
    Hi, I'm having a bit of a problem with updating to the latest package version. It's messing up some of my tower animations (not all of them) by applying a scale animation (which is not included in the fbx animation). I attached before/after video captures to illustrate the problem.

    Do you have any idea what might be causing this?
    Thaks!

    Before:

    After:
     
  45. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm not sure to be honest. I'm quite sure that I haven't change any of the code concerning animation.

    I'll probably have to look at your prefab to figure out what's wrong. If you don't mind, you can send me your prefab (along with the animation). I can have a look.
     
  46. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    127
    That is what I did. But it does not get recognized by the creeps as an obstacle then. I of course want both towers and creeps to recognize the obstacle as such.

    That is what I thought. Is there a way to automatically place and remove towers at runtime?
    In fact, it would be perfectly fine for me to be able to just place an obstacle tower when I create the scene as long as I can remove it, at runtime when I need to (and both towers and creeps recognizing the field as "empty" once it is gone.

    Is there a way to force the creeps to re- evaluate the path (like you say they do at the start of the game)? Is there a function for that, that I can call from my script?
     
    Last edited: Nov 28, 2019
  47. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    In that case, definitely use an obstacle tower. You can preplace a tower in the scene. When the game starts, it will get 'built' on the nearest node if there' one. Unfortunately there's no way to automatically place or remove tower during runtime. You will have to add your own code for that. The easiest way would be to just build and sell it. As long as you set both the build time and cost to zero it should make no difference.

    The path get re-evaluated everytime a tower is built or sold. But not in the way you imagine. It simply find the shortest path. The game doesn't check the whole scene again for empty node. It simply check if there's any shorter path based on which tower is added/removed. This is again why you should just use buy and sell for adding and removing tower. The pathing will get handled automatically.
     
  48. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    127
    Ok, so let me recapitulate. For my idea, it would be best to pre- build towers (invisible) as obstacles. When my actual obstacle object gets removed, I can sell that tower(s) and both the towers and the creeps will correctly recognize the now empty field.
    What functions in which or your scripts would I best call in order to sell a specific tower at runtime from my script?
     
  49. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Correct.

    To sell a tower, just call Sell() on the UnitTower.
     
  50. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    127
    Once again thanks for the great support bud! I really appreciate it!

    Edit: FYI, this worked like a charm! Thanks again!

    So for anyone who wants to do this in the future:
    If you want to have an obstacle that covers several build spaces and that will disappear later in the game (e.g. a building that gets destroyed later in the game). Make that object itself without any collider, then pre- build (invisible) dummy- towers in the build spots covered by that object. This ensures that both creeps and towers will correctly recognize the build space(s) covered by that object as being taken.
    Once the event that triggers the disappearance of your obstacle happens, use Sell() on these tower objects to free the build spaces again. Both creeps and towers will now recognize them as being empty.
     
    Last edited: Nov 29, 2019
    Proto-G likes this.