Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  2. 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,656
    @nnoom1986, The first one might be a bit obscured so let I'll help you out. First you need to add this function in SelectInfo class definition, in TowerManager:
    Code (csharp):
    1.  
    2. public bool IsOccupied(){
    3.  if(platform==null || nodeID<0) return false;
    4.  return platform.GetNode(nodeID).IsOccupied();
    5. }
    6.  
    Then you can simply add !sInfo.IsOccupied() to the condition in check to determine where the dragNdrop tower should be placed (should be in line180 if you are using the latest version without any modification).

    As for the rest of them, you need to point out which specific effect you are referring to. If you are referring to the visual effect from the effects, they are spawned as the child of the creep. And they don't spawned if the creep has been destroyed in the attack event.
     
  2. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    OK, maybe I was not clear. I am trying to figure out what the Editor interface is for and how I use it. There are active and inactive lists and all that. I am not 100% sure what each does. I sort of have an idea, but I want to make sure I am getting that right before I do any experiments.
     
  3. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,656
    It's very simple. Each pool is managing one prefab. activeList and inactiveList contains list of all the game-objects spawned from the prefab. activeList contains the game-objects currently active in the scene, inactiveList the inactive one and that's about it. Cap is a left-over from previous iteration and is pretty much irrelevant at point.
     
  4. nnoom1986

    nnoom1986

    Joined:
    Jan 9, 2018
    Posts:
    18
    Thanks!!

    I placed the second part of the code here:
    Code (CSharp):
    1. sInfo=GetSelectInfo(cursorPos, dndInstanceID, dndTower.radius);
    2. if(sInfo.HasWorldPoint() && !sInfo.IsOccupied()) dndTower.transform.position=sInfo.GetPos();
    3. else dndTower.transform.position=Camera.main.ScreenToWorldPoint(cursorPos+new Vector3(0, 0, 15));
    But it makes the tower disappear when it touches another tower. Am I doing that part wrong?

    For the effects not spawning as a child of the Creep GO, it appears to happen on 'On Target Effect' for Abilities.
     
  5. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,656
    The problem is when the build-point is occupied, the 'else' part of the code is used. That will place the tower a certain distance away from the camera. My guess is your tower has been place behind the terrain/platform wheren you can't see it. You can change it by doing a raycast againt the platform and place your tower on the raycast 'hit' point.

    The On Target Effect is just how I intended. I imagine it like a brief visual-effect that would be spawned at where the creeps are hit (something like a small explosion), not something that follows the creep around. For something that follows the creep, try the active-visual-effect on the effect (In EffectEditor). That is the visual effect that will last through the duration of the effect and will follow the creep.
     
    nnoom1986 likes this.
  6. nnoom1986

    nnoom1986

    Joined:
    Jan 9, 2018
    Posts:
    18
    Wow, I must have missed the new visual effect addition when I was merging changes. It works great!! Thanks!

    For the tower disappearing, I'll do that. Thank you for showing me where it was all at!
     
  7. nnoom1986

    nnoom1986

    Joined:
    Jan 9, 2018
    Posts:
    18
    In Demo_Linear, if you add a Support to Wave - 1 (I'm doing 0 delay), along with the 6 Transports, it sometimes doesn't seem to affect the first Transport that generates. It doesn't always seem to happen, so you might need to pause and restart the level several times through the game UI.

    I noticed the same thing in my game. The first creep that spawns seems to be immune to the buff, but all the following creep will be appropriately affected by it. Any ideas why that happens? Are you able to recreate it on your end?
     
    Last edited: Mar 28, 2020
  8. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,656
    Thanks for letting me know. I've fixed it and sent you a package.
     
    nnoom1986 likes this.
  9. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    Hey Song!
    Is there any downside to deactivating "raycast for terrain" when not using drag and drop and not using "free form mode"?
    I have a scene where this messes with my tower placement for some strange reason.
    Thanks!
     
  10. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,656
    It makes no difference. By using 'free form mode', the code is identifying the terrain-object (object with collider layered 'terrain') as placement point and other object with collider (with 'default' layer) as obstacle. Basically, the ray-casting is being forced to cast against terrain so the 'raycast for terrain' setting is being ignored.

    How does it messes with your placement anyway? Maybe you have certain object unintentionally being layered as terrain?
     
  11. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    Hey Song!
    I have my terrain as a terrain layer. When a tower platform intersects the terrain (even a tiny bit), the grid section of the platform that intersects appears as an invalid build point.
     
  12. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,656
    I'm confused. Are you using free-form mode? When you say terrain layer, are you using layer-31? Check the default scene. If they are working, then you must have some setting error in your scene. You can refer to the layer setting in those scene.
     
  13. nnoom1986

    nnoom1986

    Joined:
    Jan 9, 2018
    Posts:
    18
    Hey Songtan, in the PerkEditor, 'ModifyEffect > Modifier > Duration' doesn't seem to work properly.

    To recreate, in Linear_Demo:
    1. Disable 'Hide in Inspector' for the 'Stun' Ability so that you can use it in game
    2. Set Laser Tower Upgrade to target the effect 'Stun_3sec'
    3. Reset the Perk Effect Attributes and Set the Type to Modifier and Duration to 1
    4. Start the game and unlock that Perk
    5. Stun now stuns for 6 seconds, instead of 3
    I originally spotted it on my game. It seems to be adding 2 additional seconds maybe? Am I missing something, or is that a bug?

    Thank you!!
     
  14. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,656
    You are right. I've spotted a minor error that causes this. You can fix this by changing line616 of PerkManager.cs to "else effMod.ApplyModifier(perk.effect);"
     
    nnoom1986 likes this.
  15. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    Hey Song!
    My terrain is using layer 31 as the terrain layer.
    I will check the default scenes once I have a moment (since I do not use freeform mode it is not a big issue right now).
     
    Last edited: Apr 2, 2020
  16. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    Got another problem.
    I have two paths in my scene, that both use a build platform as a way point. It works alright, but when I put a tower on the shared platform, I get an error message in the Console. It only does that once.
    I don't really see any effect other than the error, but I am wondering what causes it, whether it could have any bad side effects and whether there is anything I did wrong somewhere.
    NullReferenceException: Object reference not set to an instance of an object
    TDTK.Path.UpdatePlatformPath (TDTK.BuildPlatform platform, TDTK.UnitTower tower) (at Assets/TDTK/Scripts/Path.cs:458)
    TDTK.BuildPlatform+<_UpdatePath>d__19.MoveNext () (at Assets/TDTK/Scripts/BuildPlatform.cs:142)
    UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Scripting/Coroutines.cs:17)
     
    Last edited: Apr 2, 2020
  17. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,656
    Have you modify the code in anyway or are you using the latest version? The error that you are showing me doesn't quite match the code that I have. For that reason, it's hard to say if this will break anything or not. Can you reliably replicate this? Does it happen everytime you build a tower? I can't replicate the error so I'm guessing you are probably having some setting error in your scene.
     
  18. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    I have not modified the code in those files, but I am not at the latest version because of the many modifications that I made in many other files (I know I need to check into the whole Collaborate thing). The error is replicable. It happens every time I place the first tower on the shared platform.
    Here is the section of code in path.cs in my version of the file:

    Code (CSharp):
    1.  
    2. else{
    3.         for(int n=0; n<creepOnPath.Count; n++){
    4.          if(creepOnPath[n].wpIdx!=i) continue;
    5.          creepOnPath[n].ForceAltPath();
    6.          }
    7.         }
    The offensive line (ln 458)is
    Code (CSharp):
    1. if(creepOnPath[n].wpIdx!=i) continue;
    this is the line (142) in BuildPlatform.cs
    Code (CSharp):
    1. for(int i=0; i<pathList.Count; i++) pathList[i].UpdatePlatformPath(this, tower);
    Maybe that helps?
     
  19. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,656
    Well I can't replicate the error so I'll have to guess the reason is either the outdated version your are using or one of your modification have accidentally break the existing code.

    Now you should be able to fix this by changing the offending line to if(creepOnPath[n]!=null && creepOnPath[n].wpIdx!=i) continue;. However that would not fix the root cause of the problem.
     
  20. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    Hey bud! Got another question. I really like the PointNBuild mode with the pie chart menu. Only problem is that when I use that game messages seem to be deactivated. That leaves the player a bit confused, I would think. Is there a way to activate that for this control set? If so, where would I do that?
    Thanks!

    Edit: I found it. Looks like adding this functionality would be a bit more complicated. I think I will just stick with drag and drop mode for now. Any reason why there is no info text in PoinNBuild mode?
     
    Last edited: Apr 7, 2020
  21. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,656
    I'm confused. Using PointNBuild and pie-menu doesn't turn the game message off for me. Just to be clear, which game message are you referring to? The one that pops up in the middle of the screen with message like "insufficient resource"?
     
  22. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    Yes and "no valid build point" and all that. It seems like there is a condition in DnDStatusOverlay to check whether that mode is on before the message is displayed, but maybe I am looking in the wrong place?
     
    Last edited: Apr 8, 2020
  23. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,656
    It's working for me. The code for game message and build-mode are unrelated. Changing the build mode won't affect game message.

    I think you misunderstand how it work. There's no "invalid build point" message in point-and-build mode. "invalid build point" build point only shows up in drag-n-drop mode when player tries to put down a tower in an invalid position. Showing that in point-n-build mode would be very spammy as not every mouse click is the user trying to build a tower.

    Anyway, to make sure, try build while setting the resources to zero to see if the "insufficient resource" message pops up.
     
  24. Jon_Brant

    Jon_Brant

    Joined:
    Mar 22, 2018
    Posts:
    55
    Hey again. How would I go about setting the BuildingEffect of a Tower as a child of the Tower? The pooling doesn't seem to give me a reference to the cloned effect game object as far as I can tell. Currently it's being spawned with no parent.

    Thanks
     
  25. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,656
    Yes it does. The VisualObject Spawn() function will return the game-object instance that has been instantiated. So just change line116 to following:

    GameObject effObj=effectBuilding.Spawn(GetPos(), Quaternion.identity);
    if(effObj!=null) effObj.transform.parent=transform;
     
  26. Jon_Brant

    Jon_Brant

    Joined:
    Mar 22, 2018
    Posts:
    55
    Sorry if I'm missing something obvious, but using that code gives me an error. It's trying to assign a void return value to a GameObject. All overloads for VisualObject.Spawn return void
    upload_2020-4-12_15-50-16.png
     
  27. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,656
    You are probably using an older version of VisualObject.cs. I've pm you the current one. The code I gave you should work with that.
     
  28. Jon_Brant

    Jon_Brant

    Joined:
    Mar 22, 2018
    Posts:
    55
    Ah, awesome. That sorted it out. Thanks again!
     
  29. YevgenG

    YevgenG

    Joined:
    Oct 17, 2018
    Posts:
    10
    Hello, Songtan!

    Please, may you advice with one problem with platforms?

    I was trying to make platform-path to build towers there and create mazes for creeps. But it seems that at some point I'm unable to build towers in certain squares, while it seems that there are plenty of space and they don't block path. The video is attached. Please, may you take a look and say why it might happen?

    https://drive.google.com/open?id=1CAnvyK0M9lo3dpPQMWX7OAXHpxLoCnP9
     
  30. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,656
    I suspect the problem is some collider in your tower blocking those space. Check your tower prefab, remove any collider in them.
     
  31. YevgenG

    YevgenG

    Joined:
    Oct 17, 2018
    Posts:
    10
    Checked colliders, as well as tried to use basic towers from the template, but didn't worked :( Here is range from towers to the building spot, but it's unavailable.P.S. switched off colliders on the towers completely.

    upload_2020-4-18_16-33-31.png
     
  32. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,656
    Do you have the same problem with the default scene? It's really hard to tell what could be the problem. Can you send me your scene?
     
  33. YevgenG

    YevgenG

    Joined:
    Oct 17, 2018
    Posts:
    10
    Indeed, it doesn't happen on the default scenes, though I copied the scene completely and put no other objects on/under the Surface object.
    The scene is attached. Do you need any other assets to check it?..

    Many thanks for your support!
     

    Attached Files:

  34. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,656
    I've to say, you might have stumble upon a rare bug in the path-finding code. Somehow only some specific combination of path layout and platform combination will cause this. Give me some time, I'll get back to you. In the mean, you can work with other path layout.
     
    YevgenG likes this.
  35. Jon_Brant

    Jon_Brant

    Joined:
    Mar 22, 2018
    Posts:
    55
    I ran into a similar problem. Try shifting the platform's size/position. For example, lower its size by 1, and move it back in position. I had the same issue, this fixed it for me
     
    YevgenG likes this.
  36. YevgenG

    YevgenG

    Joined:
    Oct 17, 2018
    Posts:
    10
    Hello, guys! Thanks for your advice, Jon_Brant, though, unfortunately, it didn't work for me :(

    I did in another way - copied Demo scene and edited it, instead of trying to do it in "my" scene. It worked, though still not clear why it appeared in the first place :)
     
  37. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,656
    I've traced the problem to a bug with the path-finding system. I've get it fixed and upload an update shortly. The thing is this only happen if you enable diagonal neighbour (look for the object AStar in the scene). You can disable that for the time being to get rid of the problem.
     
    YevgenG likes this.
  38. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    RobG88 likes this.
  39. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,656
    Visually it's looking good so far. Be interested to see what's in there when it's released. :)
     
    UlfvonEschlauer likes this.
  40. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    Thanks bud! I only have 3 levels finished so far. Working on 3 more before Early Access Release. Then at least 3 more levels after that. I hope you could see why I added more code to your toolkit. Some of the towers have extra animations for rotating the turrets. Some creeps have extra animations too. And there are additional idle animations, like the dancing girls on the saloon tower. Also note the train leaving the station, opening more grid squares on the playing fields. This will be a continuous theme throughout the game. Level layouts will be very dynamic through scripted events. That is why I had to modify your code a lot. I am still working on the UI. Right now it is your default look (with some minor changes), but that will change when I get to it.
    Anyway, thanks a lot for everything again. You and your toolkit are amazing and the best money I have ever spent!
     
    Jon_Brant likes this.
  41. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    Hey Song!
    It's me again (yeah, I know...). I have another issue. While play- testing my game I noticed that occasionally creeps will go back along the path when I upgrade a tower. I can sort of understand if that is happening when a new tower is built (path gets re- evaluated in some way), but this should not happen when a tower is merely upgraded, don't you agree?
     
  42. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,656
    You are right. It's an oversight on my part. The path get updated every time a tower is added/removed on a platform with no exception. I forgot that upgrade a tower to another tower prefab would do that too.

    I'll get that fixed in the next update.
     
  43. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    I guess, I will install the update into another project and then copy over the changes to my code. As you know, I am running with heavily modified code...
     
  44. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,656
    I just pm you the solution. :)
     
    UlfvonEschlauer likes this.
  45. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    Hey Song!
    So far everything is working really well. I am having some issues with the avoid clipping bool however. It seems like this is not always working and also is working in some unexpected ways (the camera moves really quickly and sometimes in ways that are not entirely clear to the player.
    Normally, I would expect it to just stop at a position closest to the obstacle, but it keeps jumping around and occasionally still ends up inside the obstacle.
     
    Last edited: May 1, 2020
  46. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,656
    Seems to be working fine for me. The question is what are the obstacle you are using, specifically how the collider is shaped and place with respect to the mesh of the obstacle object? The code is using a simple raycast to avoid having the camera to goes behind a collider. If you move the camera to clip along a bumpy surface, or somehow the mesh is bigger than the collider, you are going to end up having the problem you are describing.
     
  47. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    I have a terrain and I am just using the standard terrain collider. My biggest issue is that the collision only seems to affect the zoom factor and the camera is really jumpy that way. It just bounces around. I think it would be better if it just stopped close to the obstacle instead of bouncing around like it does now. Does that make sense?
     
  48. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,656
    That's how it works. The code perform a backward raycast from the camera pivot point (where the camera is looking at) to the camera and see if there anything in the way and adjust the camera zoom level if necessary. This is the only reliable way for clipping prevention as the camera can be rotate and zoom around. If you prefer to have the camera stopped from moving before it clips with something, you can use the movement limit. That is for you to tailor the camera movement to your scene.

    Honestly I can't be sure without seeing any footage or the terrain itself. But from your description, it sounds like it's working as intended. Like I said, if the terrain/collider that clips the camera has uneven surface, moving along that is going to cause the camera to jump a bit. You can try use a simple box collider (it has a flat surface) to cover that section to smooth the zoom adjustment.
     
  49. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    I have been using the limiter with the other scenes, but it won't work in this one. I will try some box colliders and see if that does the trick.
     
  50. UlfvonEschlauer

    UlfvonEschlauer

    Joined:
    Dec 3, 2014
    Posts:
    101
    I sent you a PM with a basic collision detection that I implemented into the CameraControl. So far it seems to work as intended.
     
unityunity