Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

2D Toolkit - 2D in Unity made simple [RELEASED]

Discussion in 'Assets and Asset Store' started by unikronsoftware, Jun 16, 2011.

  1. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You can try disconnecting the prefab after creating it? That fixes it in the case that I submitted to Unity.

    I'm not sure what causes the issue specifically, it doesn't happen every single time, but its 100% reproducible once it does happen - I've submitted the bug report to Unity, hopefully they will be able to shed some light on this soon.
     
  2. jeekun

    jeekun

    Joined:
    Aug 4, 2013
    Posts:
    2
    hi unikronsoftware,

    I want to make a tower defense game by 2d-toolkit, so I need store some location information in Tilemap and get them in the code, but i can not find how to add custom data, could you show me the way?

    thanks.
     
  3. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    What kind of location information do you need to store? There are a few functions to resolve tile position to world position, and world position to tile position - check GetTileAtPosition (that takes a world position and returns a tile x y position), and GetTilePosition which does the opposite. If all of that doesn't give you the results you need, you can make your tile a prefab, and attach whatever behaviour you like to it. The tilemap tutorial has more info about this - (http://unikronsoftware.com/2dtoolkit/doc/2.10/tilemap/tutorial.html)
     
  4. jeekun

    jeekun

    Joined:
    Aug 4, 2013
    Posts:
    2
    Thanks for your reply.

    I'm sorry but I didn't express my idea well...
    I mean the Objects-Layer in other tiled map editor, something that never rendering, like some way points for the NPC, so I could make the npc walk along the points in my code.

    Blow is a sample data I used in TiledMap 。 It's like "Objects" groups.

    <layer name="Background" width="27" height="20">
    <data encoding="base64">
    *****
    </data>
    </layer>
    <objectgroup name="Objects" width="27" height="20">
    <object name="Waypoint0" x="887" y="292"/>
    <object name="Waypoint1" x="438" y="296"/>
    <object name="Waypoint2" x="429" y="22"/>
    <object name="Waypoint3" x="22" y="23"/>
    <object name="Waypoint4" x="24" y="493"/>
    </objectgroup>
    </map>
     
  5. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You can't store them in the tilemap, as the tilemap purely stores tile data and not arbitrary game data. You should create a gameObject and store this information on there instead, or write your code in Unity and use gameobjects for that directly.
     
  6. YUSHI

    YUSHI

    Joined:
    Jul 7, 2012
    Posts:
    19
    OK,Thank you very much.
     
  7. radnetro

    radnetro

    Joined:
    Apr 30, 2013
    Posts:
    6
    Hello, I was using Playmaker and 2D toolkit but when I tried to create an FSM Component that detects collision. When my Player/Character collide with a box, it doesn't detect by playmaker? but when the box was drop on top of my Player/Character the collision was detected.

    I wanna know how the collision detection works between Playmaker 2D toolkit. thanks. :)

    Another thing, how do I stop animation back to the first frame of animation?

    *the player use Character Controller generated by Playmaker
     
    Last edited: Aug 5, 2013
  8. kMak

    kMak

    Joined:
    Aug 5, 2013
    Posts:
    11
    When can we expect Part 2 of the Whack-a-Mole tutorial?
     
  9. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    First thing - You might find better help on the Playmaker forums, probably worth checking there.
    By "detect" a collision, how are you doing that?
    The collision doesn't really have anything to do with 2D Toolkit here, its pretty much Unity character controllers + Playmaker. You might get a much better and more specific answers on the Playmaker

    With the current playmaker actions, you can Play the clip and then immediately Stop it. That will set it to the first frame. There are better ways of doing this in code, but please feel free to request more specific actions on our forum thread (http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,1954.0.html).
     
  10. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hopefully, before the first 2.2 beta is released, maybe in the next 2 weeks or so - the tutorials are done, but will need proofreading and the more complicated parts simplified, and lots of testing to make sure all the steps are correct before getting released.
     
  11. radnetro

    radnetro

    Joined:
    Apr 30, 2013
    Posts:
    6
    Playmaker has a Collision Event Action, it detects whether an object is colliding with the one you specify on tag.

    $coll1.PNG

    Here shows that the collision is not detected.
    $colide.PNG

    Here shows that when I drop the box from above and manage to collide the box in that angle, it detects a collision that is why the State change to State 2.
    $collide2.PNG
     
  12. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    @radnetro - I don't know what the issue is here, it could be any number of things. I recommend asking on the playmaker forums as this is very much a Playmaker question. Your sprites don't really play any part here, you should get the same result if you used unity cubes, etc.
     
  13. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    2,960
    I'm working with a relatively huge set of sprites now, and it's making me wish for some sort of bulk renaming. Set a base name, add number starting at whatever and count up, for entire sprite collections.
     
  14. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You can easily code something like that in there. The objects are just normal Unity serialized objects, and can be manipulated pretty easily. Automatically naming things is tricky, especially if you have some naming conventions. How do you decide on numbers? Ultimately a custom solution will be best here.
     
  15. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    2,960
    Yeah, but it would be nice to have that functionality in the toolkit to clean up the imported names ;)
    Deciding on names would be two boxes of data - a name and the count to start at.
     
  16. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Given an arbitrary selection of sprites, how would you then decide the order in which to number them?
     
  17. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    2,960
    To me it wouldn't matter. What I'm doing is a sprite collection of similar items (fruit, for instance), and numbering them all fruit0 to fruit63 in any order would simplify scripting later. But it's clear I'm the only one in the world needing this :)
     
  18. FarzanZand

    FarzanZand

    Joined:
    Jul 29, 2013
    Posts:
    14
    Hi there! I just purchased unity toolkit and I love the way sprites are handled, but I am having trouble with collisions where I want the player to walk on sprite platforms.

    I have tried lot's of things and sometimes it even seems to work. Best I have managed to do is having the sprite stand on the ground and sometimes just slowly pass through, or fall over (I lock rotation to cancel this). But to do that I had to increate the z-value of the ground-sprite to 1000,.

    Idea: Create a simple platform the sprites can stand on, and collide with other sprites, just like your box demo or polygon collider demo.

    execution:
    I create a player-sprite, give it a custom box collider so it covers entire body and then add a rigid body physics.
    I then create a ground-sprite, give it a custom box collider to its proportions and let the other sprite fall on it, but it just passes through.
    Increasing the z-value of the collider box doesn't work because it gets reset to 0,2 every time I press play. The documentation on your website doesn't really go through this part.

    What am I doing wrong?

    Best regards,
    Farzan
     
  19. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You can set the collider depth in the sprite collection setting. Once you change that, commit and you should be good. If you're missing collision entirely it could be that the z positions are too far a away? If you're trying to create a player it's probably worth investigating the character controller. It tends to work better than a rigid body if you're making a platformer.

    Edit: it's still worth getting your rigid body falling properly and resting on the ground, getting gravity working the way you want, etc.
     
  20. FarzanZand

    FarzanZand

    Joined:
    Jul 29, 2013
    Posts:
    14
    I am going to experiment with the player controller for the player. It sounds like a great idea, thank you, but I will probably have non-player objects falling at some point.
    The collider depth could not be set in the sprite collection setting though. It was only x/y that could be set but I noticed that if I set the collider type to user-defined, I could increase the z-value in the inspector and it would stick.
    Both my sprite and ground is at the same z-value (0), and as long as I have no speed or fall from a tiny height, I stand on it or pass through partly. The ground only slows my fall, but not stopping it to a complete halt if I drop with some speed. Only when I increase z on the collider to about 50 does it allow me to fall on it from great heights, which is of course no problem but does higher z-values on colliders take more memory space or lower performance in any way? If not, I'll just put all colliders on 50 and that should fix it. :)

    Best regards, Farzan.
    Thanks for an excellent asset by the way!
     
  21. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    There shouldn't be any issues with large z depths.
    Be sure to constrain the z position, x and y rotation on your rigid bodies.

    Glad you like it :) check out our forum - lots of useful tips and tricks to get started there.
     
  22. FarzanZand

    FarzanZand

    Joined:
    Jul 29, 2013
    Posts:
    14
    Constraining positions sure did help, and I changed the pixel per meter from 1 to 20 and all physic laws balanced out after that. I appreciate the help Unikron! I should be able to get started from here. :)

    One last question, what is the point of pixel per meter? I feel like it has a huge point that I am missing. Is it beneficial to have it at 20 instead of 1?
     
  23. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You can set pixels per meter to whatever you like, hit setting to 20-64 tends to work best with default physics. It depends on what your pixels represent.
     
  24. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
  25. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,036
    i have the latest version. i cannot set clear flags on camera as solidcolor.it changes selection to Color. i made my game for ipad resolution. on iphone 4 there are gaps. i want this gaps as black. i cannot do it with 2dtk. what should i change?
     
  26. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    If you're using the tk2dCamera, the tk2dCamera now manages the camera. It should work fine if you set tk2dCamera.CameraSettings.clearFlags instead.
     
  27. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,036

    i use tk2dcamera and i try to change settings from inspector. when i select solidcolor from tk2dcamera clearflags dropdown it changes it to color automatically. with this setting (color, not solidcolor) it behaves like skybox. when i set skybox material to a black colored material it solves my problem.
     
  28. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You see a "Color" setting in there? You're not meant to. What version are of tk2d and Unity are you runninng?
     
  29. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,036
    unity 4.2
    tk2d 2.1 final hotfix 1
     
  30. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    I shall investigate this.
    Edit: Yup, I get both SolidColor and Color (they are exactly the same value in the enum, hence it switching to Color immediately). They are both aliases to one another, and you only get one of these in Unity 3.x, which is a bit strange. I'll fix it so it shows exactly the same thing as the camera editor in the next version.

    Anyway, I can't reproduce the issue you're experiencing with the skybox. With or without the skybox, setting to SolidColor or Color gives me exactly the same result - no skybox. Can you reproduce this in an empty scene?
     
    Last edited: Aug 20, 2013
  31. bubbalovesponge

    bubbalovesponge

    Joined:
    Nov 8, 2012
    Posts:
    69
    Odd but seems that your Whack a Mole simply crashes when you download the complete demo.
    Also, the Sprite Manager never seems to work. Followed every steps and always get the size limit error and nothing.
    Do you have any demos besides the standard scene demos when you purchase since those really do not show much.
    Like, background animation scene, collision with objects, charater movement, etc?
     
  32. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Crashes how? What version of Unity / 2D Toolkit are you using? If it crashes Unity, what happens if you then reload the project? Do you get any error messages with the crash? We've not had anyone report any issues about crashing so far.

    Those demo scenes only show you how to use the features relevant to the toolkit - since the toolkit uses Unitys physics engine, you'd simply use a character controller, etc. to move your character. You'd use a rigidbody for physics, etc. We don't demonstrate "specific" features or things which you'd use Unity for. For instance with background animation scenes - as you could implement that in any number of ways, and ultimately would depend very much on how your game is structured.

    The more "specific" features are the focus of the game tutorials. There's a new breakout game tutorial due for release with 2D Toolkit 2.2 which focuses on different things than the whack a mole game. There's also the second part to the whack-a-mole game that'll hopefully be released then.
     
  33. benthroop

    benthroop

    Joined:
    Jan 5, 2007
    Posts:
    141
    Awesome, awesome toolkit Unikron. Thanks so much for making it!

    I'm having a hard time working with Quaternion.LookRotation and tk2d sprites from a top down orientation. I can't find a good upvector to make the lookat work. A solution is to put the sprite underneath another gameobject and then do the LookAt on the parent, but for other reasons I don't want this. I want to be able to do the LookAt directly on the sprite.

    One solution I could see is for tk2d sprites to have an option to natively be constructed facing up (facing +Y), such that their rotation is still 0,0,0. Is this possible? Is there another solution that I could try?

    Thanks!
     
  34. benthroop

    benthroop

    Joined:
    Jan 5, 2007
    Posts:
    141
    I think I'm seeing a bug...

    I have a prefab that is a hierarchy of tk2d sprites with mesh colliders. I place the object in the scene and then duplicate the object in the editor, resulting in object A and object B both referencing the same prefab. I'm seeing a bug where destroying object A in game causes object B's mesh collider to go missing. It would appear that they are sharing the same collider data. Is this a known issue?
     
  35. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    In this case, the best solution would be to simply write your own "LookAt" function. Something like this will probably do the job
    transform.rotation = Quaternion.Euler(0, 0, Mathf.Atan2(relativePosition.y, relativePosition.x) * Mathf.Rad2Deg - 90);
    We still don't know what "forward" is on your sprite, so you'll have to adjust the rotation appropriately. The above assumes Up on your sprite is forward, but it could just as easily be Right.
     
  36. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    That is a known issue if you're doing this at runtime using Instantiate, but I guess you're doing this in the editor? Probably a bug if so. What version of Unity tk2d?
     
  37. benthroop

    benthroop

    Joined:
    Jan 5, 2007
    Posts:
    141
    4.2.0f4 Unity

    Not sure where to find the version of Tk2d but there is an update available for me. I'll grab it and see if the behavior persists.
     
  38. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You can check the version in 2D Toolkit > About
     
  39. benthroop

    benthroop

    Joined:
    Jan 5, 2007
    Posts:
    141
    I updated and the issue is still happening with TK2D 2.1 Hotfix 1.

    Let me know if you want something for repro...
     
  40. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Would appreciate it if you can send to support at unikronsoftware dot com. Should be straightforward to sort out if I have a repro.
     
  41. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    390
    Is there a way to tell on a touch device when a person has a finger down outside the button then hovers over the button while still holding the finger down? Button down doesn't pick this up.
     
  42. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    No there isn't at the moment. Button down only gets triggered when you click "inside" the button collider.
     
  43. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,197
    Hey Unikron,

    Is there an exact process, step by step way, to properly import a .tmx file from apps like Tiled to a TileMap in 2D Toolkit.

    I went through the tilemap tutorial here:
    http://www.2dtoolkit.com/docs/2.10/tilemap/tutorial.html

    And downloaded the "tiles_spreadsheet.png" tilesheet.

    I used that tilesheet to then make my level in Tiled and export it as .tmx format.

    From there I followed the rest of the TileMap tutorial.

    At the end I imported the .tmx file I had from Tiled. Everything is correct, except for the tile id's in 2D Toolkit. Is there something I'm doing wrong? Do I need to use separate sheets for Tiled vs 2D Toolkit?

    Example of wrong Tile id's:

    Here's the level in Tiled:
    $tilemap1.png

    Here's the level imported into 2D Toolkit's TileMap:
    $tilemap2.png
     
    Last edited: Aug 27, 2013
  44. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287

    This should work fine and still does in my test case, but the test case was created way back when the feature was first put in.
    Can you please email a repro case to support at unikronsoftware dot com, including the tmx so I can take a look at this.
     
  45. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,197
    I just sent you a repro at support. The subject line is: Repro Case: TMX File Does Not Import Properly Into 2DToolkit
     
  46. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Thanks. It'll make it much easier to track down / fix.
     
  47. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,197
    It's might also be worth mentioning I'm using Unity3.5.7. DId you get a chance to take a look at the issue and what may be causing it, or is that going to take some time? Thanks.
     
  48. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    I'll get a chance later tonight to look into it. Don't worry, it'll be easily fixable whatever it is ;)
     
  49. acmshar

    acmshar

    Joined:
    May 4, 2010
    Posts:
    24
    I got 2D Toolkit when it was on sale, but only just had a chance to try the tutorial today. This system seems pretty great. A couple of notes from the tutorial:

    For Unity 3.5 (I know, I know) all I had to do was : replace .activeSelf with .active == true and SetActive with SetActiveRecursively

    For the scoring (in 2.10 docs, maybe this is fixed in 2.2), I think you got the ternary operator backward. It should be: ScoreScript.Score += mole.Whacked ? 10 : 0;

    I have a question about dicing atlases. I can see why it is important for the background, but why shouldn't I just dice everything? I'm guessing it isn't a great idea to do so for something you call to animate often. Best practices?

    Also, any plans to do a tutorial with a controllable, animated character? I'd be interested in seeing that.

    I also messed around with UIToolkit last week and really like it. Looking forward to doing more work with 2D and UI Toolkit.
     
  50. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hi there,

    Thanks for the feedback about the tutorial - I'll pass the bug report to the author.

    To be honest we'll be perfectly happy supporting 3.5 indefinitely, if not for ONE problem - with the UI stuff, it becomes almost impossible to use properly with SetActiveRecursively. You'll probably have seen all the nasty workarounds in place to support that. Also about the UI - we're trying not to call it UIToolkit to avoid confusion with Prime31's UI Toolkit!

    About dicing sprites - the reason you don't want to animate those is that animating those is considerably slower due to having to change the indices. If/when there is a quicker way to animate these in Unity, that could become the preferred way to deal with things. You may get artefacts when scaling down with diced sprites too, so keep that in mind when deciding to do this. Having said that though, if you only have a couple sprites that you need to animate, then you could just bite the bullet and do this without any adverse effects. Really depends on what you're doing.

    We've got plans for some more tutorials, for sure. One more ready to go with 2.2 as well :)
     
    Last edited: Aug 31, 2013
unityunity