Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[Released] 2D Platform Controller

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

  1. Drowning-Monkeys

    Drowning-Monkeys

    Joined:
    Mar 6, 2013
    Posts:
    328
    This is weird - when I replicate your ladder video, and the hero character gets to the top of the ladder, he stands for about a tenth of a second, then falls back to the step that's under the top step and hangs there. Any thoughts why that's happening?
     
  2. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    WIll try to take a look at that on the weekend, will likely require a bit of customisation.
     
  3. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    The standing for a tenth of a second would be the character still in the "climb to top" state (gravity doesn't get applied in that state). Why he falls through the top step is not so obvious, possibly I forgot to add some settings on the prefab or maybe theres something slightly different about your setup. Does the ladder in the HeroSample work for you? Would you mind sending me your project so I can take a look?
     
  4. Drowning-Monkeys

    Drowning-Monkeys

    Joined:
    Mar 6, 2013
    Posts:
    328
    Ah - it's when i use HeroCharacterWithDamage instead of HeroCharacter. They seem to be using the same animations so i don't know what's up with that, but that's what it is.
     
  5. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    There are some new settings that define where the character will be positioned after a ladder climb (because these animations often move the characters root). I expect I didn't set them correctly on all the prefabs.
     
  6. Drowning-Monkeys

    Drowning-Monkeys

    Joined:
    Mar 6, 2013
    Posts:
    328
    Yup the climb offset was 0'd out. Man I was freaking out a little thinking i was the only one with broken code ;)
     
  7. S0ULART

    S0ULART

    Joined:
    Jun 14, 2011
    Posts:
    131
    Hello Johnny!
    Is it also possible to create topdown 2D games with 4 or 8 axis movement like the old zelda games or binding of isaac http://www.youtube.com/watch?v=zIs2IQx7jV0 with your platform controller?
     
  8. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    No there is no support for that kind of behaviour.
     
  9. Drowning-Monkeys

    Drowning-Monkeys

    Joined:
    Mar 6, 2013
    Posts:
    328
    JohnnyA,

    Found an interesting bug. If you create a ladder, and disable "Dismount with Arrows", run towards the ladder pressing DOWN, when the character passes the ladder, he will become stuck until you release the DOWN key.
     
  10. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Thanks will check it out.
     
  11. lightassassin

    lightassassin

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

    Just wanted to point out a bug a tester of mine pointed out.

    If you grab a ledge sometimes it goes to the second head collider causing the player to be hanging from inside the platform. I tested real quick on the Hero example with the ladder and it happens with your defaults in the sample scene also.

    To recreate it, get close to the edge of the platform from underneath it, and when jumping move toward and quickly move away and back toward (right left right on arrow keys/d-pad) and sometimes the edge detect will go with the back of head collider and then face the character the correct direction while being inside the platform (looks... cool ^_^).

    If you need a video let me know, and I'll whip one when I get home.

    Also the ladder issue noted for HeroWithDamage prefab is a setting problem for climb offsets. The standard Hero prefab has the correct settings (and timer for animation). Temp fix for people would be to create a new inspector window and lock it to show the Hero prefab, then select the HeroWithDamage one in their default inspector and copy the variables that are different.

    Not that it matters when you have your own custom character with animations. =)

    I may have a question for you later in regards to ladders ledge climbing but I will have to wait until I get home for the details.

    Again excellent work on all of this, saved me heaps of time, and is one of the big reasons I'll be able to enter the Windows Comp!

    Cheers,
    Ben
     
  12. Apouchkal

    Apouchkal

    Joined:
    Aug 24, 2013
    Posts:
    3
    Hi Johnny,

    I use your tool. It's very useful but I search to created an Action button, and link it with your anim script.
    If you can help me.

    Apouchkal
     
  13. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Howdy mate,

    thanks for the info. I think it may just be the direction checker as I fixed that bug in the core code in 1.6.x (unless its another similar but still different bug). I'll need to make a couple of minor updates to fix this but would you mind running your test cases on a character without a direction checker (direction check is only required if your character is not symmetrical or if you want a different method of determining the facing direction, for example follow mouse).

    - John A

    PS If you want to quickly fix your direction checker:

    1) Expose ledgeHangDirection as a public property form the RaycastCharacterController.
    2) Use that as your direction in your DirectionChecker so it overrides anything else (see code for CurrentDirection property for a sample).
     
    Last edited: Aug 25, 2013
  14. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    I'd say you probably should create a new method in the animator, for example DoAction(). When this is triggered you might set a flag that overrides the other animations while it is true. You may also want to stop your input in your input controller so the action can complete. Once complete go back to normal operations.

    A sample of this will be in a future release maybe in the next 3-4 weeks.
     
  15. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,418
    Hey Johnny, exactly how can I stop the input my Buttons which move the CharacterController?
     
  16. AaronG9688

    AaronG9688

    Joined:
    Aug 26, 2013
    Posts:
    6
    Hey JohnnyA, have you tried to implement inertia at all? Like in mario, when you are running in one direction, and you either stop or switch directions, you don't immediately go full speed in the other direction; there is a deceleration that happens before you reach full speed. I'm trying to implement that in the controller, but I'm having trouble figuring out exactly how, and wondered if you had any tips for me.
     
  17. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Thats in there already... there are two settings that will effect it acceleration and drag, and theres even an animation state that gets sent (SLIDING). To make your character slide around you will need to reduce drag and acceleration, try halving the existing values or maybe halving them again (not in front of my Unity machine so I can't test exact settings). In the end it will require a bit of experimentation to get it to feel like you want, but shouldn't be too hard :)
     
  18. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    You should consider SimpleInput as a guide but for production release you will likely implement your own input (which extends RaycastCharacterInput). For example to stop input in your controller you could add an additional variable (stopInput) and if its set to true you don't change the values for x/y/etc.

    Code (csharp):
    1.  
    2. // Existing code
    3. x=0;y=0;jumpHeld=false; jumpDown = false;
    4.  
    5. if (stopInput) return;
    6.  
    7. // More existing code
    8. ...
    9.  
     
  19. AaronG9688

    AaronG9688

    Joined:
    Aug 26, 2013
    Posts:
    6
    Awesome, got it feeling nice now. Thanks for the quick reply! :)
     
  20. mjdonizetti

    mjdonizetti

    Joined:
    Jul 2, 2013
    Posts:
    5
    Are you still planning to release that attack system?
     
  21. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    somethink's about avatar for retargeting animation on another player
     
  22. S0ULART

    S0ULART

    Joined:
    Jun 14, 2011
    Posts:
    131
    The attack system will be part of your 2D platform controller I suppose?
     
  23. tonyel4

    tonyel4

    Joined:
    Jul 4, 2013
    Posts:
    10
    Hi Johnny!

    Where you able to look up how to do wall sliding or sticking with moving platforms over the weekend?

    I have been trying to implementing it on my own but I haven't been able to make it work so far
     
    Last edited: Aug 27, 2013
  24. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Yes, but after the Adventure Kit... so probably a while a way yet.

    No its a separate package (and separate purchase) which can do any number of combat type games. It will however be built with the 2D Platform controller in mind for easy integration.
     
  25. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Sorry I completely forgot. Can you send me an email so I can put a star next to it in gmail (which is about the extent of my current TODO system).
     
  26. Mad_Fox

    Mad_Fox

    Joined:
    May 27, 2013
    Posts:
    49
    Hi, my first post here, awesome controller, it's helping my project a lot. i have a simple question regardin inertia like mario (like AaronG9688 posted a few post up), if i decrease acceleration and drag in the settings when i walk or run and stop touching anything the character slides perfectly, but i have a problem when i switch directions, it doesnt slide, just swap direction and start accelerating full power to the other side, and look weird, can you help me making the turn not so abrupt?
    Thanks in advance, you are making a great job!
     
  27. msbranin

    msbranin

    Joined:
    Jan 19, 2009
    Posts:
    104
    Were'nt you going to add at least a standard generic attack. I asked about it a while back and you said you would whip something up
     
    Last edited: Aug 27, 2013
  28. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Yes but that's somewhat different to the attack system which includes combos, special attacks, stun, block, etc.
     
  29. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    That should be addressable by changing (lowering) acceleration. You may also want to look at reducing the value sent by the input controller, but usually that's not needed.
     
  30. AMO_Noot

    AMO_Noot

    Joined:
    Aug 14, 2012
    Posts:
    431
    Makes sense; combat like that, or even more simple combat wouldn't really fit thematically in a Platformer Controller package.

    But, does that mean that the Swimming update will be next? Been eagerly awaitin' that one. :D
     
  31. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Push/Pull is next, really not much to do on that one.
     
  32. lightassassin

    lightassassin

    Joined:
    Mar 29, 2013
    Posts:
    45
    Heya Johnny,

    Sorry for the slow reply, been a bit busy. Anyway, here is the video as I promised

    Clicky!

    I had a quick look through the code and forced the direction etc... Looks like it will still pickup the rear collider no matter the direction. Thinking it needs an extra check for which collider is the front one based on direction before it does the ledgehang check. The ledge climb offset is using the right direction each time so at least that is working ;)

    Hope the info helps, I'll look into it myself later if you don't have time.

    Cheers,
    Ben
     
  33. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Oh yes that was intentional, it is planned to add an option to chose if you want to only grab the direction you are facing but not yet implemented. Main concern is that the facing direction is correct.
     
  34. AaronG9688

    AaronG9688

    Joined:
    Aug 26, 2013
    Posts:
    6
    Hey JohnnyA,

    I've been using your stuff for a little while now and it's great. I'm currently trying to create functionality to grab a box and carry it around; but I'm a little confused about how the colliders work since it isn't using unity's physics. What I'm trying to do is, basically, when the character collides with an object, the collider is triggered; I then have an IEnumerable method called Grab() that takes care of the destruction/creation of the box. Have any quick tips?

    Edit: I didn't explain that well, but I think I have the logic down for the actual interaction, I'm just not sure how to set up the 'grabbable' box so that it can interact as a collider with the character. I'm used to "OnTriggerEnter(collider)" and "OnTriggerExit(collider)", so I'm trying to figure out how to set the physics up like that.
     
    Last edited: Aug 29, 2013
  35. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Hi Aaron,

    your explanations are a little confusing to me, and to be honest this is a complex behaviour which can be implemented many ways (I hope to provide some examples in the near future).That said I will provide some discussion which might be of use.

    For picking up the box you could have:

    1) a platform that uses DoAction() to check for a side collision
    2) a normal Unity collider that interacts with another collider you add to the character (for example how coins and things work in the alien/mario samples)

    For carrying the box you can:

    1) parent it to your character
    2) transform it in relation to your characters movement

    For affecting how your characters collides:

    1) Adjust your characters colliders (for example if he carries the box on his head you could add two new side colliders and increase the length of the head colliders.
    2) Have the box work like a character (this is what push pull demo here does... each box is actually a little "character").
    3) Don't affect collisions at all.
     
  36. lightassassin

    lightassassin

    Joined:
    Mar 29, 2013
    Posts:
    45
    A big old OHHHH. Well that explains all that then. I'll just write a a direction checker for that then.

    30 days until the competition... things getting fun =) Hope your entry is going well =)

    Cheers,
    Ben
     
  37. AaronG9688

    AaronG9688

    Joined:
    Aug 26, 2013
    Posts:
    6
    AHA! Thanks, that works much better. The DoAction/parenting to character method is a good place to start. The physics of the box (typically using a rigidbody) is making the box lag behind the character though, and without the rigidbody, it has no gravity. Should I write my own gravity for the object or can i use rigidbody physics with some tweaks?
     
  38. Mad_Fox

    Mad_Fox

    Joined:
    May 27, 2013
    Posts:
    49
    Hi johnny, a simple question, im trying with no suceess to implement a second jumping animation in the "doublejump" state.
    im reassigning a different state to the double_jumping state and the assigning an animation but im doing something wrong cause nothing happen.
    thanks in advance!

    Edit: i think i discover whats happening, its triggering for a frame the animation that i assign, but the problem are the "airborne" and "fall" animations overriding my doublejump
     
    Last edited: Aug 30, 2013
  39. Ylex

    Ylex

    Joined:
    Apr 9, 2012
    Posts:
    14
    Hello, is 2D Platform Controller standalone asset, or it can be used only with 2D Toolkit? Thanks.
     
  40. msbranin

    msbranin

    Joined:
    Jan 19, 2009
    Posts:
    104
    It can be used with 2D toolkit and comes with an example mario type scene using 2D Toolkit. The newest demo on the first page of this thread uses 2D Toolkit for the graphics.
     
  41. Dan_Tsukasa

    Dan_Tsukasa

    Joined:
    Jan 26, 2013
    Posts:
    155
    Hi Ylex.

    The answer just above seems to have slightly missunderstood your question so I'll try instead.

    The 2D Platform Controller is a standalone Unity Plugin and doesn't require 2D toolkit or any other unity plugins in order to function, there is however a 2D Toolkit example project amongst several other non 2D Toolkit projects, this is just to show how it can be integrated into 2D Toolkit if needed.
     
  42. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Jump is sent only on the frame that the jump occurs. You need to use the animation layering/buffering to ensure the jump/double jump animation plays (overriding other animations). Depending on which animation method you use (2D toolkit, Legacy, Mecanim, Orthello, etc) you may need to write a few lines of code to ensure the animation completes before playing the next one (for example buffer the next animation in a variable and play it when the previous animation completes).
     
  43. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    I've decided to push out push and pull as it is. It works quite well within a given set of constraints (e.g. no slopes). I think the key with platform physics is to implement small simple solutions that address a particular need (instead of trying to write generic behaviours).

    With this in mind I will aim to produce more physics samples over time based on the types of things you guys want to do in your games. So let me know what you want to see.

    - John A

    EDIT: I'll also inlcude a couple of other simple physics samples like this:


    [video=youtube_share;On2khFaVV0s]http://youtu.be/On2khFaVV0s
     
    Last edited: Aug 31, 2013
  44. bravery

    bravery

    Joined:
    Mar 26, 2009
    Posts:
    270
    Hi JonnyA,

    I'm wondering can I use this kit to build a 2D infinit running game?

    Thanks.
     
  45. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Last edited: Aug 31, 2013
  46. bravery

    bravery

    Joined:
    Mar 26, 2009
    Posts:
    270
    Thanks for the quick reply,

    can you please giude me how to make the controller and the camera similar to the video?

    Thnaks in advance.
     
  47. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    The camera from the Mario sample is pretty close to what you need.

    For the input use the SimpleInput but instead of resetting X back to 0 each Update leave it fixed at 1 (if you want to always run).
     
  48. Dan_Tsukasa

    Dan_Tsukasa

    Joined:
    Jan 26, 2013
    Posts:
    155
    Hi Johnny, whilst this is something that can be added quite quickly and easily most likely, will the push and pull examples actually use push and pull animations, its pretty unnatural in the above example to see someone simply walk into something to move it. That said! I've been waiting for this update, its the missing puzzle piece for my game so to speak.
     
  49. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Yes, example above was just something I whipped up in a few minutes, but I'll add push(and maybe a run while on top) animation. I assume you have seen this: http://www.youtube.com/watch?v=ZXASuxhMHgE
     
  50. Dan_Tsukasa

    Dan_Tsukasa

    Joined:
    Jan 26, 2013
    Posts:
    155
    Ah yeah I've seen that before, completely forgot about those animations.
    Looking forward to this update, I imagine it should be in the UnityStore in 1-3 days (depending how long unity takes to push it through) if you've already submitted it as said above. Thanks for the speedy reply Johnny, surprised you're still awake, considering the timezone you're in.