Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Released] 2D Platform Controller

Discussion in 'Assets and Asset Store' started by JohnnyA, Mar 11, 2013.

  1. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Hopefully that means everything is working now :)

    One thing to keep in mind is its best to consider the animators as samples; you will generally need to do special stuff to suit your own character animations (maybe he picks his nose when he is idle for 6.5 seconds) and I recommend creating a new animator class based off of the sample closest to your animation approach. This way you can update the code as needed without affecting the main kit.
     
  2. Dan_Tsukasa

    Dan_Tsukasa

    Joined:
    Jan 26, 2013
    Posts:
    155
    Hey JohnnyA

    Quick question, for going forward, updates etc (barring 2.0 which you mentioned would be a complete overhaul and likely not at all compatible with anything here). are you planning on using only mechanim and unitys 2D Animation and physics for updates or will you continue adding updates to the 2D Toolkit version too, since thats still using 2D Toolkit animations and sprites and not the Unity method.
     
  3. Kafar

    Kafar

    Joined:
    Nov 29, 2012
    Posts:
    220
    Hi Johnny,

    I read this thread above, it's still valid or for this case the current version have new workflows? In my specific case I have some sprites about the same character with different size so I cannot set colliders in a good way for all size.

    Thanks in advance.

    -Kafar
     
    Last edited: Nov 30, 2013
  4. Lolinternetpoker

    Lolinternetpoker

    Joined:
    Jul 15, 2013
    Posts:
    3
    Is there something wrong with the swimming? I cant get the example scene to work and I tried it in one of my scenes and still no luck.
     
  5. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    2DTK only provides the animation the behaviour classes are shared by them all. Worse case you have to add a handler for the new state which is only a couple of lines of code. Which is not really an answer. How about this: I probably wont update the sample scene I probably will update the animator.
     
  6. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Hi Kafar,

    there are a few options, but there is no special workflow to handle this case as it doesn't come up very often (in fact first time :).

    If your sprites are specific states of the same character then your options are using transform (i.e. translate transform when state changes) or applying new collider settings (i.e. change distance or position when state changes).

    If its only when your character changes entirely (for example getting a power up) you can do the same or alternatively just swap in/enable another prefab (so you have separate set ups for all characters and just enable the one that matches your current power up).

    How you work out and store the transform/new settings is up to you. A simple way would be hard code the settings (probably quite reasonable if its only for a couple of states) or provide some simple behaviour which enables you to "Transform X by Y when state Z occurs". A more elegant way would be to add a serialise functionality so you can adjust colliders as needed and then save the settings. At runtime you could load them back and apply as needed. This would be nice but is probably only worth it if you have many different shapes to handle.

    If you need some help with the technical aspects of implementing one of those solutions contact me via the support email address.
     
  7. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Could I get some more information? Sample works for me, although I think the setting sprobably need a little tweaking (maybe a bit less gravity and a lower max speed).

    When you say it doesn't work ... what happens when you go in to the water and hit the space bar? In the default settings you have to keep hitting space ideally about 1-2 times per second. Each hit performs a stroke which adds a little bit of momentum. You can turn autoswim on in the SwimmingControllerInput.

    When you hit the water the swim should fire... it could be a physics settings issue (character not colliding with water). Did you import project settings? It might be worth adding a breakpoint or Debug statement in to the SwimmingTrigger class to make sure its firing.
     
  8. Kafar

    Kafar

    Joined:
    Nov 29, 2012
    Posts:
    220
    Hi Johnny,

    Thank you for reply! My case is the first then I think to apply new collider settings.

    Do you have any idea about a sprite with actual 2 animations (walk and idle) why when I change between them there's a flicker for a second?
    Thanks in advance.

    -Kafar
     
  9. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    What animation system are you using (Legacy, 3D Mecanim, 2D, 2D ToolKit, etc)?
     
  10. Kafar

    Kafar

    Joined:
    Nov 29, 2012
    Posts:
    220
    2D Toolkit
     
  11. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Is it in both directions or only for Walk back to Idle? If so do you have a slide animation? Is the slide state being set (you can attach an AnimationLogger script to see which animations are sent).

    When you say flicker what exactly do you mean. Is it an empty frame? Is the character in a spot that it shouldn't be? Is there a mismatch between an idle and walk frame? Is it a frame that you wouldn't expect to be played at all?

    Might help if you slow time scale down so you can see exactly what the 'flicker' is.

    Finally its probably better to use email to work out this kind of issue: support@jnamobile.com
     
  12. lightassassin

    lightassassin

    Joined:
    Mar 29, 2013
    Posts:
    45
    Hey guys,

    Just wanted to throw some info up for those that are asking questions. I am not going to directly answer any, just giving you an idea of what can be done with this excellent asset =)

    So I have been working on a 2d Co-op Action Platformer, 4 players either by network or local (all 4 on one pc/mac). I decided to use the Tnet asset after fighting with unity networking (ugghhh), and 2DPC has been excellent to work with, nice clean code, and very simple to integrate the networking parts (be it unity or Tnet). Using Johnnys example code (I code locked at version 1.7 I think), I created a battle system (health, attacks, attack timer, attack block) and it has all been simple due to Johnnys code being so clean.

    With animation I am using Spine with a double state machine setup (just made a copy of johnnys state machine setup for second one), meaning my attack animations are applied only to the body parts they effect while the main state such as running still takes place. AI is pretty simple for my game, and takes alot from Johnnys example AI controller. Also, it is used directly with Tnet to control the AI across the network (excellent!).

    TLDR: 2DPC is great for anything co-op, networked, action based (real time attacks) and is simple to integrate with Spine animations. I am not a expert coder (self taught) and never worked professionally coding and this asset has been great.

    Anyway, I really need to get back to working on my game, after missing the MS contest the scope of the game increased and some changes have been made for making he game more fun =)

    Thanks and good luck guys,
    Ben
     
    Last edited: Dec 1, 2013
  13. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Glad you are having a good experience, I can't wait to see your game... when can we expect to see it (or a video of it)?

    - John A
     
  14. Lolinternetpoker

    Lolinternetpoker

    Joined:
    Jul 15, 2013
    Posts:
    3

    Ended up not needing the water part so no problem here. Thanks for the reply though!

    EDIT: Tried fixing it anyways and got it to work by adjusting the gravity override.
     
    Last edited: Dec 2, 2013
  15. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Okay, good stuff.
     
  16. lightassassin

    lightassassin

    Joined:
    Mar 29, 2013
    Posts:
    45
    Next week I'll have a nice trailer up. I got a bit behind on time after changing how the game played (had to admit to myself it wasn't as fun as I'd hoped), racing the clock for the competition wasn't the best way to try make a game =D Also trying for a demo the week after.

    Important thing is it's all coming together nicely now. Though wish I wasn't working full time, got the majority of my work done when I took 2 weeks off of work.

    Cheers,
    Ben
     
  17. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Can't wait, make sure you post or link it here :)
     
  18. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    If you are using custom platforms/velocity controls you may notice an issue with some velocities not being applied ... seems I introduced a bug a few versions ago and it managed to slip by unnoticed (because of settings it could be unnoticable to you).

    Here's a fix just incase (will be in the next version of course).

    In RaycastCharacterController2D line 1064:

    velocity.y = 0.0f;

    should be:

    if (velocity.y < 0.0f) velocity.y = 0.0f;

    Same in the non 2D Version on line 1060.
     
  19. SteveXu

    SteveXu

    Joined:
    Jul 22, 2013
    Posts:
    15
    Hi JohnnyA :
    The sides. These colliders push the character left and right when they hit obstacles. I hope you add a "ignore" Layer to ignore sides colliders. This is useful to add some fences to stop enemy fell off a cliff but the character can walk through .
     
  20. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    All colliders operate only against one layer, so ignore wouldn't make sense yet. I've been thinking about making this a list of layers, but most use cases for this have a better solution which is why it hasn't been a high priority item.

    For example in the case you suggest I'd think that this would be much better handled by the AI than the geometry. You could do something as simple as a hard coded number, you could use triggers that tell the enemy to turn around, or even make your enemies smart enough to detect that there is a cliff and not walk off of it (the sample AI kind of does this, although you can use his momentum to trick him off the edge).
     
  21. mousse

    mousse

    Joined:
    Oct 3, 2013
    Posts:
    27
    This is roughly my issue with the current controller is that it's just so unwieldy.. super, super excited for 2.0 now. You rock man.
     
  22. Credd

    Credd

    Joined:
    Dec 4, 2013
    Posts:
    6
    Hi,

    I had some questions about movement.

    As far as I can tell, MovementStyle.DIGITAL makes the character either stay still, move at walkSpeed or move at runSpeed.
    And I can't seem to get the desired movement with MovementStyle.PHYSICS_LIKE. I'd like it to not use acceleration or drag, but use RaycastCharacterInput.x directly. (Ie. if x=0 I'd want the character to instantly not move at all, and if x=0.5 I'd want the character to instantly move at 0.5*speed).

    So basically I was wondering if it was possible to use the RaycastCharacterInput.x directly as movement input, or if there was some other way to get the desired effect.

    Thanks.
     
  23. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Try using DIGITAL and updating walkSpeed/runSpeed directly from your input controller (obviously it will need a reference to the character controller).
     
  24. Credd

    Credd

    Joined:
    Dec 4, 2013
    Posts:
    6
    Ah, that solves it for x movement. Thanks.
     
  25. WACOMalt

    WACOMalt

    Joined:
    Jul 17, 2012
    Posts:
    11
    I am implementing this controller for my game, and I have run into two problems. When my character jumps from a rope, he is stuck rotated at whatever he was when he left the rope,

    I cant get swimming to work at all, I read the manual and tried to mimic the swimming example, but no matter what my character doesnt behave any differently int he water trigger volume at all. What could I be missing?
     
  26. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Likely need more information for both of these. For 1 how are you animating (Mecanim, 2D, Legacy, 2DTK)? Are you using a custom animator?

    For 2 Does the swim sample work for you? Are you sure the water trigger is triggering (for example have you debugged or logged it). When you say you tried to mimic swimming example does this mean all the settings are the same? The gravity is the most noticable factor.
     
  27. The_Daleatron

    The_Daleatron

    Joined:
    Nov 26, 2013
    Posts:
    43
    Hello ello again, wondering if anyone help me out with a little problem here.
    I have my animations set up, and when i am moving to the right my character faces left and vice versa.
    Now im not entirely sure why this happening, i though it may have been about the axis it was facing before i imported then as fbx
    so i opened the example her and just change my guy so he was in the same direction. But that did nothing.



    im using the model animator script and the simple character controller. Im not really what information i need supply to get help with this, also is their a forum for this plug in cause i dont want to be spamming your topic with my nooby issues sorry ;)
     
  28. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    I've got a feature request/cool suggestion

    In addition to the ladder climbing and rope climbing already available, it would be cool to have wall climbing. Kind of like the wall sliding that's already there but instead you could climb up and down.

    To make it even better you could climb on surfaces with different angles and the character would rotate (like it does now on ramps).

    to make it even better-er you could transfer from climbing on the side of a surface to hanging below it (think monkeybars) when it gets to a certain angle.

    This could make for some cool rock climbing mechances or something!
     
  29. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Edit the animator code in the check direction function (theres a comment in there mentioning you may need to flip 90 to 270 and 270 to 90 depening on your model) or go in to a 3D program and rotate your model by 180 degrees in z.

    If you want to avoid spamming the topic just use the email address at the top of the product documentation.

    - John A
     
  30. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Wall climb has been mentioned before, it shouldn't be much hassle (kinda of like wall stick with an extra command). That said attack system is next priority so not sure when I'll take a look at wall climb (maybe soon as it sounds simple).

    - John A
     
  31. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    Don't forget crawling! :D
     
  32. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    I really should write these down. Crawling is another easy one... the only reason I didn't add it when I did crouch was because I didn't have any animation for it!

    If you don't hear thats crawling is in by Monday, then send me an angry email :)
     
  33. The_Daleatron

    The_Daleatron

    Joined:
    Nov 26, 2013
    Posts:
    43
    Last edited: Dec 5, 2013
  34. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Thats more about the animation than anything else. If you took existing climbable layer and added it just next to a roof, then had a platform based animation override you could do that pretty perfectly with existing system. The complexity is in syncing up the animation with the bars.

    Maybe I should have a look at getting a new character done for the 2.0 version ... any animators out there that would be willing to do the work for a reasonable (i.e. cheap :)) price?
     
  35. The_Daleatron

    The_Daleatron

    Joined:
    Nov 26, 2013
    Posts:
    43
    Ow ok, i dont know alot about unity and the whole animation states thing yet. I really should look that stuff up.

    I could make you like a block man rig, with a simaler set up to mine in the vid above but i have to use the legacy setting for that so im not sure
    if that would be a problem for you. Animation wise kind of a busy time of year with stuff going on and all of that, it would depend on the time frame.
    Sure send me a message if your interested. Show Reel
     
  36. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    Yeah I think a modified ladder would work well for monkey bars so long as you don't care about syncing with the individual bards (a much harder problem but not important unless it's for literal monkey bars). In a perfect world there would be a way to seamlessly transition from "wall climb" to "monkeybar climb" like if you were on a wall that suddenly rotated!
     
  37. ulutais

    ulutais

    Joined:
    Dec 6, 2013
    Posts:
    2
  38. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    You can't use root motion and the controller together. The controller needs complete control of the position of the character. For walking/running movements you have to use the controller (you can still tweak animation speed using mecanim blends), for more complex movements like climb you can bake the root motion in to the animation.
     
  39. nitekrawler

    nitekrawler

    Joined:
    Dec 8, 2013
    Posts:
    13
    To Johnny A.

    Thanks for this awesome and amazing tool. This asset has almost every single feature that I needed to get started on my game. I do have a few questions/ feature requests for you:

    1. What needs to be altered so that I can replace the jump button with the entire screen minus the portion taken up by the joystick instead of a smaller traditional button?

    2. Will you be adding an inspector feature to make a custom number of jumps? Say I wanted to have a hero controller that could jump 4-6 times like Kirby in Smash Bros.

    3. Have you thought about adding a Dash and Back Dash that many Platform games like Castelvania have?

    4. Any more concrete information about how you will be implementing attacks in your next update especially in regards to how they will colllide with other player characters?

    5. With the current 12 raycasts per character controller do you think a 4 person game would be possible on tablets?

    Thanks again for all the time you've spent in supporting your users with this wonderful and amazing asset that you have created!
     
    Last edited: Dec 8, 2013
  40. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    1. Just create a large collider for the button that sits behind the joystick in z, you might need to stick another collider behind the joystick but in front of the button just to more clearly define an area that can't be clicked. This collider wouldn't need any funcitonality. Remember to put the buttons in a layer that the character wont collide with.

    2. Yes, I think the double jump code basically handles that already, I only need to change one variable.

    3. Someone implemented a dash not long ago. If you are using physics like movement you can just directly boost the characters movement using Velocity. Not sure if/when that will get in ... although if you keep asking it will eventually.

    4. Characters will have hit boxes and hurt boxes. When they collide damage will be done.

    5. The number of raycasts is up to you, but 12x4 should be fine on most tablets. I've had 6x12 running at a solid 30fps on an iPhone 3GS.
     
  41. The_Daleatron

    The_Daleatron

    Joined:
    Nov 26, 2013
    Posts:
    43
    I got a bit carried away messing around in maya and made something, let me know if your interested if not im sure i can use it for some thing else. ;) Pic1 Pic2
     
  42. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Hey mate I've already got an animator who will start on the updated animations after christmas but that models looks amazing! I'll send you a PM regarding the model.
     
  43. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    i want see ! based on mechanim animation ? can be usefull ! ?
     
  44. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Mecanim is already supported, but I want to get some extra animations and also provide a rig that users can update themselves.
     
  45. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Baby born and healthy... lets hope he sleeps well so I can use my 4 week break from work to get lots of updates in to 2DPC!

    - John A
     
  46. StonePaleAle

    StonePaleAle

    Joined:
    Aug 20, 2012
    Posts:
    28
    Congrats!
     
  47. MarioRuiz

    MarioRuiz

    Joined:
    Nov 7, 2009
    Posts:
    161
    Got the pack a few days ago, congrats on your newborn!!!
     
  48. Grohowiak

    Grohowiak

    Joined:
    Mar 20, 2012
    Posts:
    34
    Hi, I'm really thinking about buying this asset but was wondering if the mecanim controller that you show on your YT channel is somehow described or attached to the file?
    I want to use my custom character with your controller.
    And also I'm wondering if the animations that are included in the package can be retargeted?

    Cheers

    PS... Congratulations :)
     
    Last edited: Dec 13, 2013
  49. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    Any updates on crawling?

    Edit:

    Oh my god, I totally didn't read your last post Johnny! Congratulations!!! :D
     
    Last edited: Dec 13, 2013
  50. gruddlebug

    gruddlebug

    Joined:
    Mar 11, 2013
    Posts:
    65
    Congratulations!!!