Search Unity

[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
    Hi Parnell,

    the controller just sends state events, it doesn't know anything about your 3D model or 2D sprite set-up. You need to set up the animation controller to suit your models/sprites.

    The ModelAnimator makes an assumption that your model will face 270 degrees when running right and 90 degrees when running left. This happened to suit the models I was using from 3DRT for testing (and is due to the use of the 'back' view... see below).

    The character's velocity is available through the Velocity property, if you want to speed up the animations you could use this to affect animation speed.

    To be clear the model animator is a sample. When you build a game you are going to need to write a more complex animation controller that does all the things that fit your game (for example do you want to play a slide animation, or play a particle effect or ignore the SLIDING animation completely).

    As for front and back, it makes a lot more sense to me for moving something to the the right to increase its x position, this is how every graph/diagram I have ever seen works, thats why I set the scene up that way. Also if I write Transform.translate(Vector3.right) I'd like it to move to the right on the game view (which it does from the "back" view).*

    Regards,

    John A

    ----

    * Just to clarify in a 3D world it makes perfect sense for the front view to move a character to the left of the camera when they move right ... the character is moving to their right not to the cameras. But this is a 2D engine, and it simplifies things if Vector3.right = right of screen.
     
    Last edited: Apr 27, 2013
  2. parnell

    parnell

    Joined:
    Jan 14, 2009
    Posts:
    206
    Awesome! Thanks Johnny, I fixed my left/right issue with my model and reversed the tweak I made in the script. Thanks for the clarification on the camera thing, I think it's just late and my mind is mush. I appreciate you taking the time to answer my questions though.
    Can't wait for edge grabbing!
    B
     
  3. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    No problem its a good question. WIll be making it to the doco in the next version.

    ---

    I'm working on ledge hanging now but I have some issues. I'm not sure how an animator would animate ledge hanging (in terms of where the character would be in relation to the origin). Would they offset the character (and thus whilst climbing I don't actually move the character), or would the centre on the origin (in which case I move the character to suit the animation)?

    Usually this is not much fo an issue, but ledge climbing has quite involved interaction between character position and animation (characters hands need to stay fixed to the ledge and their body moves around them).

    Can anyone help?!?
     
  4. zebualvi

    zebualvi

    Joined:
    Apr 14, 2013
    Posts:
    11
    Hey JohnnyA, how can i add fall health damage in it? Higher the fall = Greater the damage.

    Thanks.
     
  5. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Just a quick reply as I'm about to leave:

    Using platform mechanism create a platform that checks characters velocity in DoAction. You will need to attach the script to every platform in your game that can deal damage (maybe all).

    Alternatively you could create a script attached to the character which checks velocity each frame and compares it. If the change is too large (i.e. from -10 to 0) apply damage.

    Just some options, let me know if you need more help and I will get back to you when I have some more time.

    - John A
     
  6. blaize

    blaize

    Joined:
    Jul 25, 2012
    Posts:
    41
    Hey JohnnyA,

    Regarding your question about climbing animation;
    I would make the animation so that whilst climbing the hands stay at a certain position, and the body moves around it. just like it would in real life :)
    This would also make the animation process easiers i think, it would give the animator a look of what the exact outcome of his/her animation wil be.
     
  7. JohnnyA

    JohnnyA

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

    that seems to be the general idea. I still think its going to be a bit of work for the animator to get it looking perfect but I can't really see any way around it.

    What I envisage is the following:

    When edge hang is initiated, the EDGE_GRASPING event is sent and the character "box" moves to an offset position which would generally be overlapping the ledge, the time taken to do this is user specified. Users can also specify this offset, and can use 0,0 if they want. For example a 3D animator might want to set the root bone at the top of the ledge and "hang" their character from this.

    Once the character reaches the hang position the EDGE_HANGING event is sent.

    When the player presses up the EDGE_CLIMBING animations event is sent. The character doesn't move for a configurable number of milliseconds (in this time the user can play their animation moving about the hands).

    Once the time is up the character sends the EDGE_STANDING event and the transform moves back to its original position, the time it takes to do this is also configurable. Finally control reverts back to normal.

    It's still going to be a little bit of work to ensure the animation smoothly moves back to the right position without bobbling during the EDGE_STANDING phase.
     
    Last edited: Apr 29, 2013
  8. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    My fall damage script is kinda dumb, but I do it based upon fall time. I added a public getter for falltime and if it exceeds the amount of a normal jump I start tracking its length and when the player IsGrounded again I check fall damage. I throw out small values (so the player doesn't take small damage from slightly abnormal falls) and if its past that threshold I calculate the damage and apply it.

    When I tried to do it based upon velocity the problem is sometimes velocity would change even though we were still falling and also I didn't want to make terminal velocity falls automatically fatal and yet I also wanted to make sure a fall of sufficient length would be fatal. If it's a bottomless pit the player passes through a collider that applies fatal damage.

    I haven't gotten around to integrating any of the last few versions of the controller into my game (I stupidly edited the controller directly so I need to move those additions to an extension or something and import the latest version), but I was thinking with the changes to character state noted in the last version I might be able to use that in the future.

    Re:Ledges It seems pretty hard to make something abstractly and without using any physics or ragdoll elements on a 3D character (attach the hands and let the rest flop?). I would think for stock animations you would want the center point to be wherever the point of connection with other objects is happening and you would adjust your animations to suit that.

    I think other ledge climbing asset store packages have their own character and animations instead of trying to engineer a generic solution. I think your best bet would be to come up with something that works for your own test character and then have it documented so people can customize it to fit their own particular animation needs.

    EDIT ha didn't see the last post by Johnny. That solution sounds good to me.
     
    Last edited: Apr 29, 2013
  9. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Thanks for all that info. I think I'll include a fall damage solution in the next update. It's something that will just be much simpler if its integrated in to the controller.

    As to editing the main controller code... darn! I understand the need for it, but it does make it hard to keep up with updates. The animation updates in the last version are pretty important too :s

    One thing I would suggest is if you can't do something in the controller without editing the base code let me know!
    I can suggest a solution that doesn't require editing the main controller, or provide a controller update which will be on the main branch and so will make it in to the next update. Of course I can't guarantee that it will be included in a timely fashion but I will certainly try.
     
  10. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    I've got bad habits from always being a solo coder. I'm sure whomever is maintaining my code from my last job loves my insightful comments like //this sucks and needs to be improved

    An easy addition that I think makes a lot of sense is a public getter for the player's platform. Part of the design of my camera system is to avoid moving in the Y direction as much as possible which I think is generally the best practice for a platformer However once the player is attached to a moving platform the camera hard locks in both X and Y (ignoring the push box) to the player. Giving the camera system an easy way to check if the player is on a platform and info about that platform was an easy solution.
     
  11. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    If the character is parented then you can get the platform from a public property as of the last few versions :)
     
  12. parnell

    parnell

    Joined:
    Jan 14, 2009
    Posts:
    206
    Hi JohnnyA
    So i'm adding in a simple 1 frame jump animation. As i'm finding the jump will happen the animation will be stuck in that look/state for a while after landing on the ground. I'm trying to figure out why this is happening and can't see to figure it out. Also, I made an 'airborne' animation as well and set that up in the scripts so that it's available and I don't see it pop up either.
    Any idea why this could be happening? I can send you the project if you like.
    Thanks again
    B

    EDIT:
    I cranked the Airborne priority up in the public enum CharacterState and I'm seeing the airborne animation play now however when he lands now the airborne animation is still playing for a while then the idle plays. Do I need to put the idle animation priority above everything else?

    EDIT pt2:
    I adjusted both the Airborne and Falling priorities WAAAAAY up ( and Falling above Airborne). This seems to have solved that issue. I need to look at Sliding a bit as well, but I'm figuring this out. I just hope I'm doing it correctly;)
     
    Last edited: Apr 29, 2013
  13. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    It's very unlikely that you would need to change the built-in priorities. And you definitely don't want IDLE to be above everything else. Attach the AnimationLogger to your character to see if the events are being sent correctly. Jump should be sent and then immediately after (i.e one frame) airborne should be sent.

    Welcome to send me your project if you would like (john at jnamobile dot com).

    Regards,

    John A
     
  14. parnell

    parnell

    Joined:
    Jan 14, 2009
    Posts:
    206
    Thanks JohnnyA.

    One thing I noticed would be good to have is a 'land' state. It'd play after fall and would bd interruptible by the player too.
    B
     
  15. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    For land just check the previous state (i.e. if current state = ILD E and previous state = FALLING) you landed. This way you can support landing at different speeds too (i.e play a different animation like a forward roll if current state = RUNNING and previous state = FALLING).
     
  16. Moraleidahgo

    Moraleidahgo

    Joined:
    Mar 3, 2012
    Posts:
    107
    The release date for the new update is scheduled for today. Will it really come out today?
     
  17. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Unfortunately I haven't updated that for a while.

    For the ledge hanging stuff I really need an animation to test with. So its waiting on me hiring a modeller/animator. I'm hoping it wont be *too* far away!
     
  18. parnell

    parnell

    Joined:
    Jan 14, 2009
    Posts:
    206
    I'll help.
    Let me know what you need.
    B
     
  19. ZacCom-Corp

    ZacCom-Corp

    Joined:
    Apr 5, 2013
    Posts:
    10
    How would you add attacks for the player and Playmaker support. Thanks
     
    Last edited: May 1, 2013
  20. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Having done a side-scrolling beat-em up using an early version of the controller I can say that my approach was to separate movement and attack controllers almost completely. The only touch point was an additional variable which stopped movement in the X or Y direction during combos (for example move forward while doing a dash uppercut, or pause falling while in an air combo).

    Of course the animations need to be mixed in, and in my case I sent animation events similar to the existing CharacterState (I had another set of events which sent AttackState). These animations where higher priority than the movement animations.

    There's also a whole lot of stuff you need to do in terms of synching hit-boxes to animations, etc. This is well beyond the scope of the platform controller.

    All of that said if you just want to add some simple attack, you really just need to add another button to the input controller and when the button is pressed down turn on your hit box and play the correct animation.

    ----

    EDIT: Just thinking about this I might release an attack and combo system, and although it will work smoothly with the platform controller it will be a separate product.
     
  21. parnell

    parnell

    Joined:
    Jan 14, 2009
    Posts:
    206
    Just tell me where/when to throw my money.
    Thanks!
    B
     
  22. Mistale

    Mistale

    Joined:
    Apr 18, 2012
    Posts:
    173
    @JohnnyA: There seems to be a slight problem with turning vsync off. The character movement gets slower, but movement while in the air remains the same (probably because air drag is set very close to 1.0).

    It seems to depend on the drag calculations inside of MoveInXDirection(bool grounded). The speed gets divided by drag every frame independent of frametime.

    Is this something that's fixable?
     
  23. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Hi mate, good catch, don't have the code in front of me, but as far as I remember drag doesn't take frame time in to consideration. I'm sure its fixable but I wont get a chance to sit down and have a look for a day or two.

    Thanks,

    John A
     
  24. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    Is it possible to disable the sliding?
     
  25. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    I used to have a bool for only moving when input is given, although I ended up removing it, maybe I can put it back.

    However increasing acceleration and drag should emulate this behavior very closely. Can't remember exactly what values to use but you should be able to get the right values with a little experimentation.

    As for the animation you can just ignore the event.
     
  26. ZacCom-Corp

    ZacCom-Corp

    Joined:
    Apr 5, 2013
    Posts:
    10
    Thanks for the info. Attack and combo system would be nice.
     
  27. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Hey guys, someone has posted a negative review regarding performance. I've attempted to address their issues with a post in the asset store and youtube video ( http://youtu.be/nyNd7XrjawU) , but it would be really helpful if people who are using (and liking) the product could post some positive reviews so I don't have a one star review sitting at the top :s
     
    Last edited: May 3, 2013
  28. MaToPi

    MaToPi

    Joined:
    May 3, 2013
    Posts:
    3
    Hi Johnny.

    I'm an Animator:

    Like in a jump it would involve 3 steps

    1. Climbing down - Character is standing up on the ledge, then jumps down and gets into the hanging pose. The root of the character remains fixed and only the mesh is moving down. So it would start right under his feet and end up aligned to his hands.
    2. Ledge Strafing - Think of a walk cycle. The root will be at the top position (still aligned to the hands) and the character starting in a passing pose with arms crossed.
    3. Climbing up - Again the root remains fixed at handsposition, then the mesh goes up and root ends up under his feet at ground level.

    An idle would just have the character ledging straight with the root aligned horizontally and between his hands.

    That's one way to do it.


    By the way, I just bought the controller and is AMAZING !!!
     
    Last edited: May 3, 2013
  29. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Hey thanks for the purchase and the notes.

    Just quickly are you a 2D animator? What you describe is what other 3D guys have described to me, and that's what I will be doing (with the extra steps described a page or two ago). But I want to make sure I am catering for 2D folks as well.
     
  30. MaToPi

    MaToPi

    Joined:
    May 3, 2013
    Posts:
    3
    Sorry I'm a 3D animator, but I'm guessing during this action the root should always remain at the edge of the ledge regardless of the animation type.
     
  31. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    So a few people have offered to help with the animations for ledge hanging and the like. I think the best bet is to create a character that I can add to the package. So my question:

    Is anyone willing to create a character (he/she/it can be really simple) and create the following animations (minimum): idle, run, jump, fall, ledge hang/climb, wall jump, and ladder climb.

    I would need the character to be able to be included in my asset store package with no license restrictions although it wouldn't need to be exclusive. For this exercise I'd prefer legacy animations, although having Mecanim available too would be great (thats my next step).

    In return I can offer you consulting time to help you code your platformer (or other game). I'd be happy to do a like-for-like time exchange as long as the animations aren't going to take a long time (ideally a couple of days).

    If you are interested please PM me with a link to a couple of animation samples and a timeframe for delivery (i.e. can you do it in the next week or two).​
     
  32. cc0919

    cc0919

    Joined:
    Apr 5, 2013
    Posts:
    17
    Hey Johnny,

    Really cool package. I've been attempting to get it working with a tilemap engine (specifically Tidy) and the prefab character is falling through,despite the tiles having box colliders. Any idea what I'm doing wrong? I know that isn't much of a description, but I thought maybe you know of a common problem people have when doing this kind of thing.
     
  33. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    You would need to have the box colliders on a layer the raycasts can "see". Check your layer collision matrix under Project Settings / Physics as Tidy may be putting its tiles on a different layer. Also check your Background / Pass Through / Climbable layer settings on the controller.
     
  34. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    What he said :)

    The layer of your background (platforms) should match the "Background Layer" specified in the RaycastCharacterController.

    The other thing, which is simple but worth checking just in case, ensure your z settings are the same for the character and the tiles.
     
  35. cc0919

    cc0919

    Joined:
    Apr 5, 2013
    Posts:
    17
    Thought it was the matrix, but it was actually because both my climbing layer and background layer were set to 0. Thanks for the help!
     
    Last edited: May 4, 2013
  36. brundi

    brundi

    Joined:
    Apr 29, 2013
    Posts:
    1
    Hey Johnny,

    Thanks for a great asset! Just got the 1.3 version, was hoping to see wallslide support in this release, is that still on the roadmap?
     
  37. JohnnyA

    JohnnyA

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

    Wall Cling/Slide is definitely on the agenda and is planned for the same release as Ledge Hang/Climb. I've stalled a bit looking for an animator (or maybe thats just an excuse) but hopefully I can get back on track shortly. I will update the schedule in the next day or so.

    - John A
     
  38. blaze

    blaze

    Joined:
    Dec 21, 2011
    Posts:
    211
  39. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    The controller uses an alternative mechanism, you don't actually need to be on the ground to jump, just close to the ground. It doesn't give you quite as much freedom as input buffering so it wont work for really lax controls, but it gives a pretty tight platform feel.

    * Note that you can implement input buffering in your input controller without affecting the core controller if you desire.
     
  40. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    The controller uses an alternative mechanism, you don't actually need to be on the ground to jump, just close to the ground. It doesn't give you quite as much freedom as input buffering so it wont work for really lax controls, but it gives a pretty tight platform feel.

    * Note that you can implement input buffering in your input without affecting the core controller if you desire.
     
  41. JohnnyA

    JohnnyA

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

    sorry I've been a bit quite for the last week, got a few other assets I'm working on (out soon).

    I've updated the release schedule in the first post to be a bit more generic and a bit less aggressive time wise. Hopefully I can stick to it.

    The animated character is underway, this will help demonstrate lots of features, particularly ledge climb.

    Stay tuned (and keep prompting me for updates :) ).

    Regards,

    John A
     
  42. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Drag with vsync off fix is now submitted to Asset Store (v1.3.1).

    Email me with your invoice number if you want it immediately.

    Note that you will need to change your drag settings a bit after updating (jump.drag setting to a low value like 0.25f, movement.drag a little higher). Technically it is the percentage of velocity you lose each second.
     
  43. didox

    didox

    Joined:
    May 12, 2013
    Posts:
    1
    Hi,

    I am thinking about using your platform controller to make a small game but i have a question about performance. I saw your performance video and 500fps on a machine like that is very good. However, how does your 2d platform controller perform when using multiple instances. For example if i where to have 50 players in the same frame all using your controller.

    Thanks
     
  44. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Hi didox, without video capturing off and vsync off its more like 1200 fps, however 50 characters is likely too many. How are you going to get input for 50 characters on one machine?

    If you are talking about enemies then you probably don't need the controller for them as it has a lot of complex stuff that enemies usually don't do (rope swinging, wall jumping, etc). What I have done in the past is use a simplified version of the controller suited to each enemy type. It only has the bits I needed and thus vastly improves performance. I've had 1 player and around 15 enemies on a mobile device using this method, so I think aroudn 50 should be okay on desktop.

    Although a simplified controller is not in the kit, I'd be happy to help you create one (and maybe I its something I can add in a future release).

    Of course maybe your case required 50 fully funcitonal characters in which case I would have to say that you probably wont achieve it with this controller.

    Regards,

    John A

    --------------------

    In other news an animated 3D character will soon be added to the release, this is primarily there to demonstrate ledge hanging, but will also be good for other stuff. This update WILL mean a price increase (likely from $25-$30) so get in quick.

    Video coming soon.
     
  45. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    Hey are crouching (including changing collider positions) and fall damage going to be in the next update? I just wanted to check before I waste time working on my own crappier version if a better way is incoming.
     
  46. JohnnyA

    JohnnyA

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

    This next update is about adding a full animated character, and including ledge hang/climb.

    I havent really thought of adding crouching. You have seen the transform attached to each raycast? For a crouch just create a transform called Head or something, connect it to your HEAD colliders, and translate it downwards as your character crouches.

    Fall damage I was planning on including but I forgot....ooops!

    Both of these are relatively simple and I have a long session planned for updates this weekend. I can't guarantee they will be in the next release but there is a good chance.

    - John A
     
    Last edited: May 16, 2013
  47. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    Somehow I never payed attention to the transform on each raycast so that took just moments to setup properly. Thanks!
     
  48. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,260
    I'm currently setting this up for my game i have a problem.

    When testing the character keeps getting stuck on the flexi rope prefabs. Sometimes they work fine i can swing, other times I can't swing or climb up or down on the rope, the only thing I can do is jump off.
     
  49. JohnnyA

    JohnnyA

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

    it might be to do with the spacing between the "steps" along the rope. Have you changed the raycasters so they are smaller than the sample?

    If its not that, the easiest thing to do would be to send me the project. As there are a lot of possibilities. If thats not an option PM me as we may need to go back and forth a bit.

    - John A

    PS Totally off point but I just found at the controller works with Unity Terrain... never tried that before :)
     
  50. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,260
    I just dragged the character prefab in the scene, used a couple of unity cubes as platforms and dragged across a couple of the ropes prefabs. I did adjust some settings to make the rope swing a little more.

    Also wanted to ask if it was possible for you to add a trampoline type platform?