Search Unity

TowerDefense ToolKit 4

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

  1. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    You can just select the tower prefab. If it's not added to the database, on the inspector, there will be a button to add it directly.
     
  2. danosono

    danosono

    Joined:
    Jan 22, 2019
    Posts:
    45
    Could anyone please provide the current layer assignments?
    The current pdf with the asset has the following:

    layer 24: ParticleSystem (not in documentation; I found this one by searching this forum)
    layer 25: ‘Terrain’
    layer 25: ‘Obstacle’
    layer 27: ‘Creep’
    layer 28: ‘Tower’
    layer 29: ‘Platform’
    layer 30: ‘Path’
    layer 31: ‘Terrain’
     
    Last edited: Feb 4, 2023
  3. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    That's pretty much it. If you want to dig deeper, you will find these layer being specified in TDTK.cs. The layer may not always be named/matched in the LayerSettings, but when a layer is involved in any of the code execution, the value is always pulled from there.
     
  4. moiena

    moiena

    Joined:
    Feb 8, 2023
    Posts:
    3
    I have tried everything but could not solve the problem, so I would like to ask a question.
    I would like to be able to tilt the platform, but when I edit the script, I am able to tilt the platform, but the mouse cursor is out of alignment with the placement of the tower on the game screen. I have tried everything to fix this problem, but I can't seem to get it to work. How can I write a program to prevent the mouse cursor and tile selection from being misaligned when the platform is tilted?
    In my amateurish way, I thought I could do it by tweaking various items of this "GetTilePos", but it was difficult.
    In case you are wondering, what I want to do is to use it in conjunction with other 2D assets such as the Flare Engine, and to do that I need to set the camera and platform to XY coordinates.
    thank you in advance for your help
     

    Attached Files:

    • 00.png
      00.png
      File size:
      276.8 KB
      Views:
      86
    • 01.png
      01.png
      File size:
      123.1 KB
      Views:
      80
    Last edited: Feb 10, 2023
  5. danosono

    danosono

    Joined:
    Jan 22, 2019
    Posts:
    45
    Moiena,

    I may be missing something and I am new to this SUPER COOL looking asset but,

    Could you just change the camera position / angle to achieve the same look? Place your camera above and looking down?
     
  6. danosono

    danosono

    Joined:
    Jan 22, 2019
    Posts:
    45
    Would this work for your situation? Just change X Rotation on the camera on CamerControl_Pivot? 2023-02-11_08h03_49.gif
     
  7. moiena

    moiena

    Joined:
    Feb 8, 2023
    Posts:
    3
    danosono Thanks for the reply.
    What I want to do with this is to use it in combination with 2D assets such as "Flare Engin", these have collider2D and most of the AI systems work in XY coordinates. For example, AI command systems such as ladder systems, underwater swimming systems, jumping when touching an enemy, etc. For this reason, we needed to orient the platform to XY coordinates. 
    After a lot of research, we are exploring if it is a shortcut to use FreeFromMode of "TowerManager" and explore how to improve it to snap it to the center of the tile!
     
  8. Song_Tan

    Song_Tan

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

    @darknside, you will have to look at the ability settings. If you have the option 'Require Target' checked for the ability, the ability has to be placed on a specific unit, either a tower or a creep depends on the 'Target Type' assigned. So if you just click on an empty space, then you get the target not valid message.

    @you are pretty much on the right track there by working on the GetTilePos(). However, a lot of it depends on the how you tilt the platforms. Are you having it align to xy plane? The function GetTilePos() relies on the platform being aligned to xz plane. If you have the platform align to xy plane, you can probably just tweak the certain parameters in the function and it should work (basically use the value in y-axis from the difference vector instead of the z-axis value). However if you have the platforms tiled at a odd angle, that set of calculation wouldn't work.
     
  9. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Have you tried check if the range works correctly at all? Just like the tower range, the ability range takes account of everything in a 3D sphere. That means it works just fine in 2D space. You shouldn't need to do any modification for that.
     
  10. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm confuse. Are we talking about towers or ability? Either way, the 'circle' that you are referring to should be there for both towers and abilities. If you are not seeing it, that's means you either have some setting error, or you have made some modification that hide it. Just go back to a default scene, test the default towers and abilities, see if they have that circle that indicate the range at all. If yes, that mean the problem is with your scene or your tower/ability setting. Now I can't help unless I know the specifics. You will need to let me know your setting (how your camera is setup etc.). A screen shot of the camera and your platform and towers in the SceneView would help tremendously.
     
  11. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    upload_2023-2-12_23-46-29.png

    So this is what I have on my editor. As you can see I can see the camera, and what it see. And I can see the range indicator in both the SceneView and GameView. I can also see the path, platforms and tower. The problem right now is you have locked your SceneView to 2D only. You need to press the '2D' button I've highlighted in the image above. That allows you to rotate the view in SceneView so you have a better understanding of what's going on.

    Right now from your screen shot I can't even tell if you have a working scene (path, platform, etc). I suspect the indicator is there but due to your camera angle and scene setup, it's not visible in GameView.
     

    Attached Files:

  12. moiena

    moiena

    Joined:
    Feb 8, 2023
    Posts:
    3
    Oh! 「float z = Mathf.Round((osZ + v.●) / gridSize) * gridSize - osZ;」 this to y! I did it successfully! Thanks for the help!
     
  13. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    @darknside, you need to modify the code in RangeIndicator.cs to fit your camera view angle. Nothing complicated, just change line94 from:

    line.SetPosition (i, thisT.position+new Vector3(x,0,z));

    to

    line.SetPosition (i, thisT.position+new Vector3(x,z,0));

    You will also need to change the alignment of the LineRenderer on the RangeIndicator object to 'View'.
    upload_2023-2-13_8-19-47.png
     
  14. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    It's hard to tell what's the problem without closely inspect your scene to be honest. I suspect the range indicator is being 'hidden' behind the white place you are using. Try change line94 in RangeIndicator.cs again to this:

    line.SetPosition (i, thisT.position+new Vector3(x,z,1));

    If this doesn't work. Try -1 instead.
     
  15. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    To really figure out what's wrong. I'll need to see the 3D view of what happen in SceneView when you move cursor around when trying to use an ability or build a tower (similar to your last video). The indicator object (SelectControl/RangeIndicator for tower, AbilityManager/AbilityTargetIndicator for ability) can be selected in the Inspector. When you do, you can actually see their transform position in SceneView. Knowing where they are can actually tell what they are not visible in GameView.

    To answer your question about using sprite, yes, that's how the indicator for ability is done. For tower, I need to draw a line for tower with fixed targeting direction and limited fov.
     
  16. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I don't understand your question. Can you elaborate? I thought the range indicator is centred around the feet of the tower?
     
  17. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    To be honest, the range indicator is centered at exactly where the calculation is performed. So if you want an accurate visual indication, and if you think the tower center is not aligned with the indicator, what you should do instead is adjust the position of the tower's mesh, in the tower's hierarchy.

    Not sure what you mean by 'could not trace where the circle of the target disappears'.
     
  18. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm sorry but I really don't understand what you are trying to say

    "why there is no circle at ability, change the point here?"
    Are you trying to say ability indicator is not visible? But change what point? 'Target Point' has nothing to do with any of this.

    "Where can I make such a substrate under the tower that I can't build?"
    You mean the grey thing under the tower? As far as I can tell your code is already doing that.. You just need to change spriteRangeBuilding.sprite=null; to spriteRangeBuilding.gameObject.SetActive(false);.
     
  19. gabrifu01

    gabrifu01

    Joined:
    Jan 16, 2023
    Posts:
    12
    How do I adjust the setting to turn down the sounds of fire in the main menu. so when you turn down the sounds of fire in the main menu, all sections are muted as well. Örnek kod var mı ? . Is there sample code? . or do I need to change the code?
     
  20. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    @darknside, you need to place the object 'circle' under the hierachy of 'Text'. It should goes like this: UI/UICamera/Canvas_Overlay/UIDnDStatusOverlay/Text/Circle. The code moves the object 'Text' to align with the tower. So if you don't do this, the 'Circle' will always stay at where it's.

    As to adjust the radius to above the tower, I don't recommend it. That circle is the actual targeting radius of the tower. What you should do instead is to move the tower sprite in the tower prefab so that when the circle shows up, it's where you want it. If you don understand what I mean, show me the full hierarchy of your prefab and I'll explain.

    @gabrifu01, you can look at the game-object UIPauseScreen and refer to the code in UIPauseScreen.cs.
     
  21. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I don't see 'Circle' visible in SceneView in your second image. If it's not visible when you can see the text, then it won't be visible at all. I suspect you got the scale or the rotation wrong.

    I'm going to be very honest here and I hope you don't take this the wrong way. What you have been trying to do, and struggling with are mostly beyond the scope of TDTK. While I'm happy to give you general pointer to achieve certain things, it's just not feasible for me to guide you every step along the way. Maybe I'm wrong but I get the impression that you still lack understanding of certain basic aspect of Unity. I suggest you try something simple first instead trying to get something as complex as TDTK to work in the way it's not meant to.
     
    toddkc likes this.
  22. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    I have to chime in to defend TDTK here. First, I don't think warnings in Rider determine the quality of an asset. Rider is designed to make you adhere to some pretty strict coding standards, and as we all know...you can ignore warnings, errors are the real issue. You used the word "error" in your post, but what you meant was "warning".

    Also, as to the quality of TDTK, I literally taught myself C# by reverse-engineering this asset to work in VR. I know it is overwhelming and frustrating at first, but we all start somewhere. You cannot seriously expect to spend $60 on the asset store and get custom one-on-one consulting to make your game. Honestly if it isn't a bug that causes the asset to not work as advertised you are lucky to get any response. Taking TDTK and making it 2D is just as complex as making it VR, and just like me, you can't seriously expect Song_tan to do that work for you for free? Let's have a little perspective here...
     
  23. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    No worries, I know translation isn't always perfect!

    As to how you find "the right values in this mess", the unfortunate response is you learn C#, and learn this asset well enough that you can find the right values. This asset was designed to easily add and edit towers, for example, but not to change the fundamental ways that towers work within the game.

    As to you being offended, that frankly blows me away. You have already received more time and assistance than you should have ever expected for something that is not a bug causing the asset to not work as advertised. The fact that we have this forum to ask questions and we actually get responses is already above and beyond. Generally you would get some copy/paste response from a customer service person who would have simply told you what you were doing was outside the scope of the asset and good luck. Again, buying this asset in no way entitles you to one-on-one consultation from the developer.

    But really this is none of my business, I just had to chime in and defend TDTK. Good luck with your game, remember nothing about gamedev is easy and we all struggle with things.

    When I was first getting into Unity I bought a popular 3D MMO asset and thought I would easily be able to convert it to 2D....that was quite the reality check.
     
  24. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm not going to claim that the code and documentation are perfect. But with the way it's done, it's perfectly adequate to get your to understand what the framework can do and how to get to work. The framework is designed to do a fixed set of things, within a fixed set of systems. It's not designed for open user modification. That's the limitation I'll admit and unfortunately this is what you are trying to do.

    I'm not trying to start an argument or try to insult you here and I'm very sorry that you are offended by that. I'm just trying to point out what I think is obvious. Take your latest question for instance, I really hope that I've misunderstood the question but it implies that you are not aware of the unity collider system. If I'm wrong, I'm sorry.

    If you are using free-form-mode (on TowerManager), yes that is the radius between the tower use to prevent other tower being built to close to any built tower.

    This is just a default Unity's SphereCollider. It's not from TDTK. I don't understand what do you mean by method.



    @toddkc, Thanks for the kind word. I really appreciate it.
     
    toddkc likes this.
  25. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    So this is how it works: when you move the tower around in free-form-mode. The code uses Physics.Spherecast() around the tower to detect any collider in the spot, identify them as obstacles to the tower you are trying to place. The 'radius' value you are referring to is use as the range of the Physics.Spherecast(). Now the reason why change collider on the tower prefab affect that spacing is that Physics.Spherecast() is ultimately detecting collider. So if you have other tower in the spot with collider, it will get detected and be treated as obstacle. This is why changing the collider size on the tower prefab affects the spacing between towers.

    To answer your question about the actual radius of the tower. If you are still unsure, it's the 'radius' value that we have been talking. I wasn't refusing to answer your question by the way. You asked in a single post, without additional explanation, a method (?) of a sphere collider so you can display it's radius? Sorry but I just didn't understand it.
     
    Last edited: Feb 15, 2023
  26. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    One last bit of advice...if you are using a translator you should probably stop getting so easily offended by what it tells you people are saying. You aren't going to get very far in gamedev without help, and if you constantly get offended by what you think people are saying they probably aren't going to help you.
     
  27. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    You specifically made comments stating that. Anyways, you clearly are ignoring my advice. Good luck, I honestly doubt you'll get very far in gamedev or coding in general with the attitude I've seen so far.
     
  28. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    If you are using free form mode. The code you are looking for is in TowerManager.cs, GetSelectInfo(). Should be in line345 to line352 if you haven't modified the script.
     
    darknside likes this.
  29. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Static function means you don't need a reference to a specific instances of the class to call it. So you can just go like this:

    TowerManager.GetSelectInfo(position);

    instead of:

    public TowerManager towerManagerInstance;
    void Update(){
    towerManagerInstance.GetSelectInfo(position);
    }
     
    darknside likes this.
  30. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Yes. But there are a few problems. First the function has 3 parameters that you need to pass. And it's not returning a bool so you can't put it in a if condition.

    For what you need, it will be better if you just modify GetSelectInfo() itself. There are a few if-else statement in the function that show if a tower is on a valid build point or not. It's pretty obvious, you can see it's the text 'Invalid build-point'. Just modify the code there to change your sprite indicator.
     
    darknside likes this.
  31. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Clearly you have introduce some error when trying to modify the scripts. Honestly I don't know what you have done. You can't modify TowerManager.cs and break CameraControl.cs. You must have a bunch of compilation errors in your console. What are they?

    I would recommend you create a new project with just clean import of TDTK. Compare with the script in the project with your own to see what faulty modification you have added.
     
    darknside likes this.
  32. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I honestly don't know how to help you here. I don't think modifying TowerManager alone would crash the Editor entirely and I don't know what else you have done.
     
    darknside likes this.
  33. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    The code for attacking is in Unit.cs Attack(). I believe what you are looking for is actually spawning of shootObject. That's in Shoot(), in the same script, just right after Attack() in the script if you scroll down.
     
    darknside likes this.
  34. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    For the one in the menu, you check the CacheOnComplete so that thing gets cached when player unlock an item.

    For the one in game scene (the levels), you check the LoadFromCache so that it will load the progress cached in the menu.
     
    darknside likes this.
  35. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    You have to keep in mind that the framework works in 3D by default. So the shoot-object is going to aim towards the target as it travels. I suggest you check the option 'straight-projectile' so at shoot-object doesn't change its direction mid-flight. Then you will need to change the corresponding code in ShootObject.cs so that it fix its rotation while traveling towards it's target.
     
  36. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I suppose I didn't make it clear enough in my last response. Why your sprite is not visible? Because it's not facing the camera properly. And why is that? Because the default shoot-object code rotate the shoot-object so it faces the target. In your case, you don't want that. You just want the shoot-object to move towards the target, while maintaining its rotation so it face the camera.

    So to answer your question: there's no specific method you should be using here, you just need to change the code to stop the rotation on the shoot-object and have the sprite on the shoot-object always face the camera.
     
    darknside likes this.
  37. danosono

    danosono

    Joined:
    Jan 22, 2019
    Posts:
    45
    Hi Song!

    If my tower model already has a labeled pivot point (not named TurretPivot), do I need to parent it with an empty gameobject named TurretPivot?

    upload_2023-3-1_6-48-49.png

    The tower is from Vsquad on the asset store.

    Thanks!
     
  38. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    No. The empty game-object is only needed when you want the mesh/model to pivot at a particular position. If your model has comes with a correct pivot point, then you can just use that one.
     
  39. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    There's coding involved here. Just using an empty transform to shift the turret rotation point. I would say unless you are using top down view, the default rotation (aiming, moving) probably doesn't apply in 2D.
     
  40. danosono

    danosono

    Joined:
    Jan 22, 2019
    Posts:
    45
    Good morning Song,

    My purchased towers and creeps are a little too big for the scale of the TDTK levels; they are sometimes a bit larger than the squares they are supposed to travel on so they overlap when on adjacent squares.

    If I scale the creeps' prefabs down, their die animation makes them initially scale = 1 (they get bigger for a moment) before scaling them down to die; in this case I will need to adjust the animations.

    What is the correct way of approaching this problem? I just want to ask to avoid doing it wrong the first time, lol.

    Thanks!
     
    Last edited: Mar 4, 2023
  41. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    The animation only control the scale locally. It won't take account of the scale of the parent transform. So what you can do in this case is change the scale of the parent transform and leave the scale of the model at 1. Basically:
    • Create an empty creep prefab with no model (this will be the parent transform).
    • Place the tower and creep model (with animator component on it) as the child transform. Make sure the scale is 1
    • Change the scale of the parent transform until the model fits the level.
    Make sense?
     
  42. danosono

    danosono

    Joined:
    Jan 22, 2019
    Posts:
    45
    Yes; that makes sense.

    Thanks very much!

    I bet this means I will need to repopulate my Creep database. I will find out lol.

    What should I choose when setting the layer to creep for my creeps (and tower for towers); I had chosen the prefab and changed the layer to creep and got the prompt below.

    Perhaps this should be set on the new parent you mentioned (for the scale problem)?

    upload_2023-3-4_11-26-26.png
     
  43. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    You only need to set the layer on the parent object. As long as you do that It doesn't matter if you apply to the child objects or not.
     
    darknside likes this.
  44. danosono

    danosono

    Joined:
    Jan 22, 2019
    Posts:
    45
    Thanks!

    I am unable to replace the prefab in the creep editor; I replace it but it still references the original.

    Do I need to remove and replace each creep that I re-parent (in order to resize)?


    upload_2023-3-4_14-56-18.png
     
  45. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    That's slot is just a reference so you know which prefab you are editing. You cant just outright replace prefab in the CreepEditor (TowerEditor too for that matter). Just add the new prefab as new item and remove the existing item that you don't want.
     
  46. danosono

    danosono

    Joined:
    Jan 22, 2019
    Posts:
    45
    RE "target that is responsible for Ability in the code"
    Is this what you are looking for?

    upload_2023-3-4_20-13-37.png
     
    darknside likes this.
  47. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    The code doesn't differentiate between 2D and 3D. It just blindly do a ray cast based on the position given and get whatever it has detected as the target. For this reason, you need to set the scene up so that's there's always a target for it. In the default scene, there's a always 'Terrain' object with collider and layer-13 in it. This is for isometric or top down camera. If you are using full 2D with camera angle along horizontal plane, you will need to set up a background object like the 'terrain' object that match the camera angle for this to work.
     
  48. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    It's very simple. First, enable the MeshRenderer component so you can see it.

    In the default, scene, this is how it looks like:
    upload_2023-3-6_22-4-54.png
    The white plane is the terrain. Since camera look downward, the plane will appear on the camera. So the raycast can detects it.

    When you set the camera angle to 0, 0, 0. This is how it looks like:
    upload_2023-3-6_22-3-24.png
    As you can see in the preview, the terrain is barely visible on the camera. And since you set the projection to orthographic, it won't be visible at all. What you need to do is rotate the terrain so it faces the camera.
     

    Attached Files:

    darknside likes this.
  49. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm not sure if I understand your question. Can you rephrase it?
     
    darknside likes this.
  50. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    In that case, check your object. For the terrain to be detectable by the raycast, it needs a collider and the layer has to be set to 31. You can refer to the 'Terrain' object in the default scene.
     
    darknside likes this.