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
    Have you actually try testing it and see how it works? The tower will detect a target within it's range regardless of direction. That means it can detect and attack target right below (or above) it as long as it's in range. However the default asset are not meant for that so it might look a bit weird.
     
  2. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    I figured out the issue. I'm using two cameras, one MainCamera and one MotionControllerCamera. I have everything working with the MotionControllerCamera except for the tower sell/upgrade ui & when you select an ability and get the radius indicator that you can use to select a point on the map and explode some creeps.
    These are controlled by the UnitTower.cs script which uses this script:

    if(buildInfo.status==_TileStatus.NoPlatform){
    Ray ray = Camera.main.ScreenPointToRay(cursorPos);
    RaycastHit hit;
    if(Physics.Raycast(ray, out hit, Mathf.Infinity)) thisT.position=hit.point;
    else thisT.position=ray.GetPoint(30); //this there is no collier, randomly place it 30unit from camera
    }

    I've been able to modify all other scripts needed to get the raycast from the MotionControllerCamera, but I am just making a public camera and dragging the MotionControllerCamera into it.
    The issue here is that the UnitTower.cs is on each prefab tower and I'm not able to simply add a public float/Camera and drag it on because there are multiple scenes and each scene contains a different MotionControllerCamera.

    Can you think of a way around this? Thx
     
  3. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    You can add this to GameControl.cs:
    Code (csharp):
    1.  
    2. public Camera motionControllerCamera;
    3. public static Camera GetMotionControllerCamera(){
    4.    return instance.motionControllerCamera;
    5. }
    6.  
    This would allow you to assign the camera component to GameControl. Then you can change Camera.main in UnitTower.cs to GameControl.GetMotionControllerCamera(). The function will pass on the MotionControllerCamera to be used for the ray construction.

    Please note that the camera variable wouldn't show up on the custom inspector. You will have to expand the default inspector to assign it.
     
  4. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    Brilliant, I will give it a go. Thanks so much!
     
  5. maxaud

    maxaud

    Joined:
    Feb 12, 2016
    Posts:
    177
    @songtan, I want to play an audio clip upon shooting a projectile- but when I try to attach it to the shootobject it gets destroyed too quickly on enemies that are nearby and the clip only plays partially. How would I go about fixing it so the audio clip plays in its entirety before being destroyed? My muzzle gameobject only sticks around for 0.1 seconds so I don't think that would be a good spot for it either.
     
  6. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I take it you have a very fast projectile shoot object and a muzzle as the shoot effect object? In this case you will have to do a bit of coding. Without needing to change too much of the core code, I would suggest you to change the effect duration of the muzzle so that the audio can play it's full length. Then use some extra coding to make sure the muzzle is visually disable after 0.1sec.

    The easiest way (not the most efficient way), is to create a script like this:
    Code (csharp):
    1.  
    2. public GameObject spawnObj;
    3. public float destroyDuration=1;
    4.  
    5. void Start(){
    6.    if(spawnObj!=null){
    7.      GameObject obj=(GameObject)Instantiate(spawnObj, transform.position, transform.rotation);
    8.      Destroy(obj, destroyDuration);
    9.    }
    10. }
    11.  
    You can then attached the script to your shoot object or shoot effect. Basically the script will spawn the object assigned to it and destroy it in the specified duration. With this you can spawn as many extra shoot effect if you want.
     
  7. maxaud

    maxaud

    Joined:
    Feb 12, 2016
    Posts:
    177
    This sort of works. Seems to only work on first shoot and after making a new tower. Is there something within the poolmanager that may be preventing start() to run on each muzzle flash?
     
  8. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I forgot that Start() only get called when the game object is first spawned. Not when it's reactivated. Please change Start() to OnEnable(). It will be called everytime the game object is activated. Sorry for that.
     
  9. maxaud

    maxaud

    Joined:
    Feb 12, 2016
    Posts:
    177
    You're good! Thanks for the help. Much appreciated.
     
  10. maxaud

    maxaud

    Joined:
    Feb 12, 2016
    Posts:
    177
    Another questions, I have a light on my tower I would like to turn on whenever the tower has a target. I see that Unit.target is protected in Unit.cs, what would be the best place to check if the turret currently has a target?
     
  11. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    You can modify the code a little by adding 'public Unit GetTarget(){ return target; }' to Unit.cs. This would allow you to access the target variable and do your check.
     
  12. maxaud

    maxaud

    Joined:
    Feb 12, 2016
    Posts:
    177
    As the type that doesn't like to modify core code so things don't break in an update, would you entertain adding this to a future version or make the variable public?
     
  13. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Sure thing. Consider it done.
     
    maxaud likes this.
  14. maxaud

    maxaud

    Joined:
    Feb 12, 2016
    Posts:
    177
    Thank you!
     
  15. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    Awesome. I'm wondering if you could tell me how to change something with the GUI? Right now if you hover the mouse over a button in the main menu, the tooltip pops up centered. I'm wondering how to get the tooltip to center over each individual button, not just center screen. I've included a picture for reference; The green shows what button the controller is pointing at and where I would like the tooltip for that button (centered on the button when highlighted) The red shows where the tootltip pops up right now, no matter what button is highlighted, it's always centered. The blue shows how when pointing at any various button, I would like the tooltip to popup centered over the button.


     
  16. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    To be honest, I don't have a readily available solution for this. This is a quite tricky thing to do given how the position of UI element is determined on screen. The reason why the current tooltip is always centered on screen is that the position is anchored to the screen and not changed at all during runtime. To have it shows up at the positon of the hovered button you will need to get the relative position of the button to screen canvas the button is in, then translate that to same relative position to the canvas of the tooltip object, while taking consideration of any UI scalling difference between the two canvas. That's just the general idea. There will be variation depends on the hierarchy of the UI elements.
     
  17. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    Very well, thank you sir.
     
  18. Xain

    Xain

    Joined:
    Aug 3, 2013
    Posts:
    68
    Hello and great job with the asset.I have a 2 questions if u answer them i'll be appreciated.
    1-)Can i make a game like Kingdom Rush with this asset like campaign, unlocking levels ?
    2-)If there is no save - load can i implement "Easy Save Asset" to work with TDTK ?
     
  19. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    1. Yes or no. TDTK can replicate a lot of mechanic in Kingdom Rush, but not all of them. The obvious mechanic that is not supported are unit vs unit combat. In TDTK, there's no player unit. Then there's the upgrade system. In short, you can do almost all the things in Kindom Rush upgrade system, just in a different way. Finally, TDTK is about building individual game level, it has minimal code support for building a campaign or a level progression system.

    2. Indeed there is no save. However you should be able to implement save system by yourself or using 3rd party solution like easy save. That said, depends on how what and how you want to save, it can get pretty complicated.

    Hope that answer your questions.
     
    Xain likes this.
  20. Xain

    Xain

    Joined:
    Aug 3, 2013
    Posts:
    68
    Thanks for answers.I guess i choosed my next game :)
     
  21. mapb2005

    mapb2005

    Joined:
    Aug 31, 2016
    Posts:
    4
    Hi Song!!
    Wonderful asset you have going on! Almost finished my game :)

    Just got a couple of questions, any info would be greatly appreciated :)

    1. Is there a way to make the creeps attack NPC structures that are already in the scene?
    2. How can I show the damage of the towers? for example: at 50% Hp the structure is on fire, or on every hit rubble will come out (most likely particle effects would be easier).
    3. Is there a way to limit the placement of a certain tower per scene? for example: only 3 canon towers can be placed per scene.
    4. Is there a way to randomise the towers models? for example: I have 3 different canon tower models and I would like to only have one canon tower button which would place one of the 3 models randomly (all three models would have the same attributes).

    Thank you so much!!
     
  22. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Here we go:
    1. You can place those structure as 'dummy tower'. Basically a tower that does nothing like a 'block' tower or a standard tower with zero attack range. They won't do anything but they will still be recognized by the creep as a tower and hence get attacked. Finally you just need to uncheck the 'can be sold' option in the TowerEditor so that the player can't sell them.
    2. You will need additional scripting for that I'm afraid.
    3. There's no way to limit the number of tower either. If you are just looking to limit the total amount of tower in the scene, this should be pretty straight forward. There a towerCount in BuildManager for number of tower built in the scene. You only need to check against that to know if you can build more tower or not. If you are looking to limit the number to certain tower. That is a lot more complicated.
    4. Again you will need additional scripting for this. You can assign multiple models for each prefab and have a script to randomy activate only one of them when the tower is built. Or you can modify the BuildManager to randomly select a prefab when a tower is build. But given the way the BuildManager is coded, this will probably require some hack.
    Hope this answer your questions.
     
    Proto-G likes this.
  23. kuolema

    kuolema

    Joined:
    Sep 22, 2014
    Posts:
    5
    @mapb2005 for your #4, I had to do that exact same thing. Just make your tower prefab and include a gameobject that contains all of the models you want to randomly select from and then attach a new script to that container gameobject with the following code in the Start() function:

    Code (CSharp):
    1. void Start()
    2.     {
    3.         int randomChildIndex = 0;
    4.         List<GameObject> childGOs = new List<GameObject>();
    5.  
    6.         foreach (Transform child in transform)
    7.         {
    8.             child.gameObject.SetActive(false);
    9.             childGOs.Add(child.gameObject);
    10.         }
    11.  
    12.         randomChildIndex = Random.Range(0, childGOs.Count);
    13.         childGOs[randomChildIndex].gameObject.SetActive(true);
    14.     }
     
    Proto-G likes this.
  24. maxaud

    maxaud

    Joined:
    Feb 12, 2016
    Posts:
    177
    @songtan, I'm trying to make a tower that shoots in a straight line and doesn't rotate at all. I tried modifying the FOV and any setting I put in there the FOV angle doesn't change at all. The red indicator of attack angle doesn't change at all.
     
  25. johnnydj

    johnnydj

    Joined:
    Apr 20, 2012
    Posts:
    211
    UPDATE: It seems to save the changes if I make SpawnManager a prefab...

    I'm having some really bad issue with the SpawnManager.
    I'm using version 3.0 and I have modifications done in other parts but not in SpawnManager.

    The problem is that once I setup how my waves should spawn, I save the scene load a different scene then load back my scene and again I have the Auto generated thing enabled and all my manually setup waves are gone...
    The issue it's not only in the editor, because in the Inspector I can also see the Auto generate enabled and having weird waves setup.

    I have read something in the beginning of the forum about an Update button in the SpawnEditor, which I don't have, but again, in the inspector is the same issue.
    I have the SpawnEditor closed when I switch scenes.
     
    Last edited: Dec 4, 2016
  26. furkankucuk

    furkankucuk

    Joined:
    Dec 4, 2016
    Posts:
    2
    Hello there I am the newest one around here I think. I am trying to understand how I can use your TDTK (unfortunately free version) But I couldn't get creep editor useful for me. I found an article that you wrote, followed the steps, still no good. I tried to use that model as a creep: https://www.assetstore.unity3d.com/en/#!/content/30232.

    Can you make a tutorial please? I would very appriciate.
     
  27. johnnydj

    johnnydj

    Joined:
    Apr 20, 2012
    Posts:
    211
    in TDTK_Class_AttackInstance there is an error with the calculation of crit multiplier

    The code needs to be changed from:
    damage *= srcUnit.GetCritMultiplier();

    to:
    damage = damage * srcUnit.GetCritMultiplier() + damage;
    or
    damage += damage + srcUnit.GetCritMultiplier(); //this is bad habit of calculating variables and not safe

    otherwise if the multiplier is less than 1, you will end up with the final damage being lower than the minimum damage if the hit will crit, because for example:

    with the old code:
    we have a 0.5 crit modifier
    our hit is 10 dmg and if we crit, we will have 10*0.5 = 5 damage

    with the new code:
    we have a 0.5 crit modifier
    our hit is 10 dmg and if we crit, we will have 10*0.5+10 = 15 damage
     
    maxaud likes this.
  28. johnnydj

    johnnydj

    Joined:
    Apr 20, 2012
    Posts:
    211
    and another bug
    in Unit.CS in the UpdateBuffStat method
    replace:
    if (regenHPBuff < buff.regenHP) dodgeBuffMod = buff.dodgeBuff;

    with
    if (regenHPBuff < buff.regenHP) regenHPBuff = buff.regenHP;

    because the HPRegen buff was buffing the dodge value which is not correct
     
    maxaud likes this.
  29. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm very sorry for being not responding to all the post earlier. For some reason I've stopped receiving notification for any new post since I last posted. I only realized that there are so many after randomly check in today.


    The red directional indicator indicate doesn't really reflect the actual fov covered by the tower. It indicator unfortunately doesn't dynamically changes it's angle, only range. You will have to replace the texture used with your own to accurately show the fov in your game.


    I'm not sure how that happen to be honest. I've been doing just that (edit in SpawnEditor and save scene) without actually losing any setting. In fact I've just tested it and it work as expected. The only reason I could think of is that for some reason your save doesn't registered? Try hit the save button on SpawnEditor before you save the scene. That would mark SpawnManager as dirty and make sure that the changes you made is saved. That or you are using an older version of TDTK that contain bugs that I've since fixed? If you haven't make any modification to SpawnManager and you don't mind spending some time testing, I could email you my SpawnManager and SpawnEditor script and see if that makes any difference. Btw the update button is something for very early version, you need not bother about it.


    Thanks for pointing these out. I'll have it fixed in the next update.


    Can you please be more specific about what you are struggling for. The animation? the creep model appear in weird place?


    Once again very sorry for my delay in respond.
     
  30. furkankucuk

    furkankucuk

    Joined:
    Dec 4, 2016
    Posts:
    2
    I mean I couldn't add a creep with the creep editor and couldn't find a way around.
     
  31. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    There should be a slot on the top-left corner on the CreepEditor. What you need to do is drag your creep prefab into that slot and it will be added to the editor.
     
  32. Chaz32621

    Chaz32621

    Joined:
    Apr 17, 2015
    Posts:
    199
    Hey song. What would be the best way to implement a mini boss every 5th level(Wave) and a Boss every 10th level(Wave).

    I am thinking I am going to have to set up conditions for when it reaches that level and just spawn a boss/mini boss on that wave and remove any creeps that spawn. But also I dont want these creeps to spawn at other waves other then mini boss and boss battles. What would be best to going about this. (Maybe 4.0 feature??) :)

    But I also want it to increase health and speed as levels become more. So I want it as a unit creep as well.....
     
  33. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Well, define boss wave. Is the boss wave any different than other wave? Does it spawn multiple creep or just one. If it just a bigger creep with bigger health pool, you can just treat it as a normal wave that spawn the boss creep prefab.
     
  34. Chaz32621

    Chaz32621

    Joined:
    Apr 17, 2015
    Posts:
    199
    Sorry. I want the boss wave to be 1 big creep with much more health. It would only spawn just that one boss but I want to make it where there are 10 different models of bosses that can spawn(maybe more). While the mini boss stage would be 1 smaller creep(with 10 different type of models that would only spawn every 5th level)

    I also want the path to be somewhat different so I was thinking of possible just duplicating the spawn manager and unit creep cs files and anything else and just call them boss manager. Unless there would be an easier way?
     
  35. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    In that case, I don't see how their are different from normal creep except the bigger health pool and they spawn alone. You can just treat those them like normal creep. Just make a creep prefab using that boss model (make them bigger if you must). You can then spawn just one of them in the entire wave. You can either set the prefab to have very large health pool, or use the override value in SpawnManager to give them high health.

    As for path, you can use multiple paths in a single level by default. Just create the path and have the boss creep use the path you want.

    Fyi, you can't just duplicate SpawnManager.cs the UnitCreep.cs and change their name. You will need to do a lot more modification in the files for this to work.
     
  36. Chaz32621

    Chaz32621

    Joined:
    Apr 17, 2015
    Posts:
    199

    Thank you I will give it a try and report back! Right now having GPU issues hahah to much stuff for my tiny mobile game. :/ I wish we had endless memory and processing power to use.
     
  37. BertramBims

    BertramBims

    Joined:
    Oct 12, 2016
    Posts:
    3
    Hello, this tool kit is Amazing, but i have a problem, i imported a larger map with the terrain objects and i can soom out enough to see the whole map can anyone tell me how to change the someout fuction?
     
  38. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Look for the CameraControl in the scene, you can adjust various camera setting there, including zoom limit.
     
    BertramBims likes this.
  39. BertramBims

    BertramBims

    Joined:
    Oct 12, 2016
    Posts:
    3
    Now how do i change the place the camera circles around? (is it possible to make the camera move to waypoints or other locations?)
     
  40. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    The pivot of the camera is actually the CameraControl object itself. So just move the transform to where ever you want. However do keep in mind that if you move it beyond the limit, you will have to adjust that to match.
     
  41. BertramBims

    BertramBims

    Joined:
    Oct 12, 2016
    Posts:
    3
    How do i make my platforms larger with the same amount of places for the towers to be (ex. i have a platform Scale 1x1x1 with 1 tower place, i make it larger (10x10x10) now theres ten places for the towers. how do i get a 10x10x10 platform with one place for the tower to be?
     
  42. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Try adjusting the grid size in BuildManager.
     
  43. Dannyt007

    Dannyt007

    Joined:
    Aug 3, 2016
    Posts:
    3
    Hi,
    Very nice asset great job !
    It is possible to add multiplayer (Player vs Player) in futur update :) ?
    Best regards,
    Danny
     
  44. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Hi Danny, I won't say it's impossible but it's very unlikely. I don't see it happen in the near future anyway.
     
  45. dustinmckay

    dustinmckay

    Joined:
    Nov 25, 2013
    Posts:
    26
    I am having a problem, that I can't understand, When I setup the camera, it sees the scene fine, but as soon asI press play, something in the event system moves the camera from my location to a zoomed in location. How do I freeze the camera, so what I see in the camera preview is what I see when I press play?
     
  46. dustinmckay

    dustinmckay

    Joined:
    Nov 25, 2013
    Posts:
    26
    Also how do I get rid of the sparkly stars?
     
  47. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    The camera are operating according to a set of parameter and constraint in CameraControl. If you want to change your camera setting, apart from the camera transform itself, you have to change those relevant settings in CameraControl. If you want a fixed camera, you can disable the CameraControl component entirely.

    You can get rid of the star by simply deleting the game-object. They are named as StarBG and placed under the hierarchy of the camera object.
     
  48. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Just a quick a notice that I'll be going away for a few days and I'm not sure if I'll have internet access. So apologies in advance if I'm a bit slow in responding to your post.
     
  49. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    All the script files (including the first person shooter script) are just normal .cs file. You should be able to open them with just about any editor. You must have alter some setting somewhere if you can access them. What exactly happen when you try to open the files?
     
  50. detomato

    detomato

    Joined:
    Aug 16, 2013
    Posts:
    54
    Hi,
    How do I set up my own FPS camera. Basically I'm going to incorporate AR function into it, so I need the AR camera as the FPS cam.

    Thanks.