Search Unity

[Released] 2D Platform Controller

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

  1. blaize

    blaize

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

    With the Unity3d 4.3 update and it's dedicated 2D physics, are you planning on updating the physics so they use the 2D version? (i'm sure it's a performance saver)
     
  2. Atmey

    Atmey

    Joined:
    Nov 3, 2012
    Posts:
    88
    Hi John,
    I like your enemy AI, but I am having some problems with setting the colliders with smaller non-humanoid creatures, is there a specific condition to set them up? Can I use a capsule or box collider?

    I get this error when the AI trying to climb a slope
    And this error when I make the feet colliders too low/short:
    Thanks,
    Atmey

    EDIT: and while at it, do you recommend a specific AI system available in the asset store?
     
    Last edited: Nov 20, 2013
  3. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    @Blaize, yes there's a functional demo on my yout tube channel and some notes on it a few pages back.
     
  4. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    As far as I know the AI systems in the store wont be of much use as the are strongly focused on 3D/FPS/NavMesh.

    As to the errors I'm not sure, Unity has recently deprecated bounds and probably made other physics changes in 4.3, I'll take a look over the weekend.
     
  5. robinball

    robinball

    Joined:
    Jan 1, 2013
    Posts:
    48
    I recently bought this pack and I'm very excited to try it out. I love 2d platformers and have been wanting to make one for ages. I was very pleased to find the Mario example worked perfectly well with Ferr2D right off the bat. Great start. :)

    I'd be very keen to see some attack options (firearm and melee) and maybe an accompanying pack for enemy behaviour. I'm not much of a programmer (I'm an artist) but I love to tinker. Given some flexible presets I think there's a lot I could do.

    Thanks very much. Once I've had a chance to knock some stuff together I'll be sure to let you know. :)
     
  6. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Thats the next update planned, but Unity 2D got in the way. I'll get the Unity 2D stuff going first and then a simple melee and projectile example will be after that.

    Regards,

    John A
     
  7. robinball

    robinball

    Joined:
    Jan 1, 2013
    Posts:
    48
    Great, thanks. :)
     
  8. Atmey

    Atmey

    Joined:
    Nov 3, 2012
    Posts:
    88
    Okay, upon further investigation, the geometry array has length of 5 but all are null, where they are supposed to be populated?
     
  9. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Oh you need to add the pieces of geometry that you want the AI to move between to that list, from the header:

    Code (csharp):
    1.  
    2. /// It takes a map of the level geometry (expected to be box colliders) and will only consider geometry added to its list.
    3. /// YOu can use this to somewhat restrict the places it will move to (by only including a subset of level geometry).
    4.  
     
  10. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    So I've decided for 2D Physics i"m going to follow Unity's pattern of creating similar classes to the existing ones but appending 2D on the end.

    It will mean a bunch of duplicate code, but trying to create classes which proxy to either the 2D or 3D classes seems fraught with issues.

    Migrating from 3D to 2D will be a bit of a pain, but I might look at creating some kind of migration tool if people are having trouble.

    This is mostly working now, I just need to create some new samples.

    - John A
     
  11. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    2d Physics:

    [video=youtube_share;UKUhy9eMotc]http://youtu.be/UKUhy9eMotc​
     
  12. Dan_Tsukasa

    Dan_Tsukasa

    Joined:
    Jan 26, 2013
    Posts:
    155
    It's looking good. Is there any chance of making the player be a physics object, I'd honestly thought it wasn't really possible without a crazy amount of special exceptions everywhere, however I came across the Unity Physics 2D platform controller and there it actually works, thats actually originally where I got the idea to use a Hinge Joint for push/pull from. As it stands now, I'm unsure if wind (from the physics 2d extension kit) would affect the player or not as he isn't a rigid body, same with things like Buoyancy, he has no weight. I'm going to try a combination of scripts from both kits to get something working but I'm interested on your thoughts.
     
  13. blaize

    blaize

    Joined:
    Jul 25, 2012
    Posts:
    41
    How does performance of the 2D physics compare to the standard physics in your older examples?
     
  14. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    No noticeable difference but I haven't measured anything. Remember that the controller doesn't use physics per se, it just sends raycasts, I wouldn't expect many gains.

    Are you having some performance issue? If so send me the details, I haven't looked at performance for a while, so maybe I've let some issues creep in.
     
  15. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Hey Dan,

    with this approach you need to write code for each behaviour. Its purposefully not using physics so that you have total control over what happens. Of course if something isn't part of the kit it means there's more work to add it (or more time waiting for me).

    With this in mind and with the new 2D physics out I've been giving some serious thought to creating a purely physics based controller as well.

    That said I'm not sure if I will include it as part of this kit. Over time sales have dropped and now with the release of some other nice (and cheaper) packages they are quite low.I still don't think any of the other packages have the capabilities of this one but they are plenty good enough for many people. Regardless, I'll probably sell a purely physics based controller as another package.

    That said if someone was using this package and sent me a nice email asking for the other I'm sure I could oblige.

    Anyways, thats my thoughts at the moment; hopefully I'm not being overly transparent :)

    - John A
     
    Last edited: Nov 23, 2013
  16. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Just about finished the Alien Sample in Unity 2D. Thinking I might add some little features that might be appreciated too.

    Sorry for lots of posts, having a lot of fun... Unity2D is nice :)
     
  17. Dan_Tsukasa

    Dan_Tsukasa

    Joined:
    Jan 26, 2013
    Posts:
    155
    Overly transparent, no no. Its like looking into a void, no signs no nothing, there's actually so little signs that I didn't just send an email over at all, nope.. not even 1 email, nope... maybe... okei yeah I'm not as good a secret keeper as you are.

    Additional to the Alien sample eh, sounds great, with a few minutes I managed to get everything from the 3D character working with 2D (you make animation calling oh so simple, I love it!), though I don't have a ledge climb animation, imagine that ones going to be a b*tch to setup as a sprite though.
     
    Last edited: Nov 23, 2013
  18. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    I don't have a ledge climb for the alien of course, but I do have another sprite sheet which has a ledge climb (pretty sure a video of it on the youtube channel ... http://www.youtube.com/watch?v=HOqvn4kTS6Q). Not really any different to set up than the 3D. I'll add this sample eventually, I should be able to use the same animation controller as the existing Mecanim Beta.

    - - - -

    Also a 2D sample running with Unity 2D sprites and physics:

    http://jnamobile.com/samples/2DPlatformController/Unity2DAlienSample.html

    (Still needs clean-up and some more features, but the basics are there)
     
    Last edited: Nov 23, 2013
  19. wolflogic

    wolflogic

    Joined:
    Oct 24, 2011
    Posts:
    7
    Any idea how far off the *2D version of classes will be? Thanks for the hard work keeping features coming!
     
  20. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    They are 100% done. Just need to write a few pages of doco to describe the slight differences between them and the other classes.
     
  21. StarAbove

    StarAbove

    Joined:
    Apr 11, 2013
    Posts:
    65
    Just a stupid question. This kit work with 3D object too, right? Like everything is 3D, except it play just like a 2d game. Thanks.
     
  22. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
  23. XxPleYxX

    XxPleYxX

    Joined:
    Jul 26, 2011
    Posts:
    41
    When the Unity 2D support will be released? ETA?
     
  24. StarAbove

    StarAbove

    Joined:
    Apr 11, 2013
    Posts:
    65
    Thanks very much, Johnny!
     
  25. msbranin

    msbranin

    Joined:
    Jan 19, 2009
    Posts:
    104
    Be sure to put a kill box in that sample for falling into the lava. I did that first thing and had to close the sample out to restart
     
  26. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Like all the samples the R key will restart :)
     
  27. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Submit today, Unity takes 2-5 days for an existing package to be approved. So should be out by the end of the week.
     
  28. Aasmund

    Aasmund

    Joined:
    Mar 20, 2013
    Posts:
    8
    Hello, I`m remaking Alex The Kid In The Miracle World. And I want to have a ortographic camera to follow Alex when hes moving. Is there
    a way to do this with PlayMaker and 2D-Platform-Controller? Haven`t tried it out yet, so I`m planning to buy this asset to use with PlayMaker :)
     
  29. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    I don't think there's much in that game that the controller wont handle. The controller includes a sample camera follow script. For PlayMaker you will have to ask the PlayMaker developers.
     
  30. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Update for built-in 2D Physics and Sprite support submitted just now.
     
  31. rumorgames

    rumorgames

    Joined:
    Nov 28, 2012
    Posts:
    48
    Hey JohnnyA, don't know if you've already addressed this issue:
    But it was bugging me, too. I found the source of the bug a few lines down from eedok's workaround.

    Just change the less than in the else if to a greater than:
    Code (csharp):
    1. // If we went too far go back to walk speed
    2. if (velocity.x < movement.walkSpeed  characterInputX >= 0f)
    3. {
    4.     velocity.x = movement.walkSpeed * (IsSwimming ? (1f - swimming.waterResistance.x) : 1f);
    5. }
    6. else if (velocity.x < -movement.walkSpeed  characterInputX <= 0f)
    7. {
    8.     velocity.x = -movement.walkSpeed * (IsSwimming ? (1f - swimming.waterResistance.x) : 1f);
    9. }
    Fix:
    Code (csharp):
    1. else if (velocity.x > -movement.walkSpeed  characterInputX <= 0f)
     
  32. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Yes its fixed in the update submitted today.
     
  33. blaize

    blaize

    Joined:
    Jul 25, 2012
    Posts:
    41
    Great work :) looking forward to future updates!
    When you implement weapons (melee,ranged) will you give the player the option to pickup weapons? if so, are you planning to add the function to pickup stuff like items and use them?

    I'm working on a project that has some basic rpg elements, and having items change player behaviour would be very cool.
    And something like keys to open doors would be a very nice addition.
     
  34. The_Daleatron

    The_Daleatron

    Joined:
    Nov 26, 2013
    Posts:
    43
    Hi, this looks great exactly what i need.
    Im primarily an animator do some modelling etc. I have no clue how to code. So that said how user friendly is this
    for a beginner getting into games dev unity. Thanks.
     
  35. johnny12345

    johnny12345

    Joined:
    Oct 8, 2012
    Posts:
    45
    can rope slide,swimming,ledge hanging and such work with 2d
    thanks
    do you also have a slide function in this package.
     
  36. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    2D Released today. When you test out the 2D samples remember to apply the project settings in the Project Settings folder (these set up layers and sprite layers for you).

    I think with a bit of help that it should be fine for a beginner, and I'm happy to provide the help you need. If you were put in a room by yourself with no internet it might be a bit tricky with zero game dev/Unity experience.

    The controller handles all of those regardless of physics being 2D or 3D. For example see the HeroSample2D. The Unity 2D animator does't have all those states in it (mainly because the Alien character doesn't have many animations). Note that you can edit the Mecanim Animator and swap in your own 2D animations to support ledge climb, etc.

    That said I do have a character sprite that has climbing and the like. Next update I'll flesh out a Unity 2D sample with more animations.

    There are several slide functions. If you use PHYSICS_LIKE movement setting you slide all the time (based on drag settings). You can also use the slippery platform script to increase this slide. YOu can also enable crouching and crouch sliding. When you crouch at speed you will slide along. This can slide further than normal slides and can slide through gaps (see here: http://www.youtube.com/watch?v=dmYX560rusQ ... note those slides are a bit exaggerated to show the feature).

    Finally 6-8 pages back is a script which makes you slide down hills.
     
    Last edited: Nov 26, 2013
  37. JohnnyA

    JohnnyA

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

    affecting behaviour via items can already be seen to in the 2D ToolKit example (when you get the mushroom you change sprite and gain the ability to float). I might look at doing something like this for weapons, but not in the first release.

    Although things are always growing I'm not expecting to have an RPG like item/inventory system in the near future.

    Keys to open doors is pretty simple, I'll grab some scripts form one of my other projects and include that in one of the demos (probably the new Unity2D demo the castle could do with a door). Will try and do that this weekend.

    - John A
     
  38. mousse

    mousse

    Joined:
    Oct 3, 2013
    Posts:
    27
    Hows 2.0's timeline coming along now that 2D physics has hit and all that?
     
  39. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Once attack system is done that will likely be the last major 1.x update. I'll then hold off on further development on 1.x and move everything over to the 2.x approach. Very tentatively I'd say Attack system will be Dec/Jan and 2.0 should be late Feb.
     
  40. The_Daleatron

    The_Daleatron

    Joined:
    Nov 26, 2013
    Posts:
    43
    Thanks for the reply johnny, i purchased it the other night, was having a snoop around it looks great got me real excited. Im just working on some of my animations for it then il give it a proper go. :D
     
  41. mousse

    mousse

    Joined:
    Oct 3, 2013
    Posts:
    27
    Do you see 2.0 being a huge logic change or mostly just a moving things around so its modular?
     
  42. Dan_Tsukasa

    Dan_Tsukasa

    Joined:
    Jan 26, 2013
    Posts:
    155
    Is there any chance you'll be adding Push/pull to the Mechanim character or the 2D Character at all?
    I'd already added it in the old method, but the new unity animator system is, in my opinion, rather confusing, lots of states and priorities and trying to figure out how to add something new to that is just way beyond me, so even if the push animation for the 2D Character uses a random animation, so long as its a seperate state I should be able to make use of it from there anyways.

    Will there be a 2D Physics Rope in the next update.
    I know it might sound silly, but I think its quite difficult for a lot of us to switch code from 3D Physics to 2D Physics, so having all of the 3D Prefabs have duplicates as 2D Prefabs will be really useful for a lot of people such as myself.
     
    Last edited: Nov 28, 2013
  43. The_Daleatron

    The_Daleatron

    Joined:
    Nov 26, 2013
    Posts:
    43
    Is their any video's that are a bit more in depth than the one of the first page in regards to adding your own 3d character with animations, I have been trying to add Mine and i set up the scripts as given in the examples, but when i go to animation element list and assign my animations, nothing happens. I have them broken down into idle/walk/run/jump etc but when i hit play in the game window it just keeps stopping.
     
  44. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    The idea will be you can sub in different "blocks" to do different movement controls. Kind of like the existing MoveInX and MoveInY functions but more generic. So the existing stuff will be broken in to blocks (so for example ladders will be a different block to swimming which is a different block to normal movement, etc). Platforms can have their own blocks if they have special movement. Power-ups can have their own blocks. You then can switch movement by choosing which blocks to use (and there will be built in switching logic too, e.g. it will move to the ladder movement logic block when you latch to a ladder).

    2D Rope will be in soon. Push/Pull animation states for Mecanim/2D will come at some stage, will at least take a first look this weekend, but not sure they will be in the next release.
     
  45. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    No there is no more detailed video at this stage. The HeroAnimator expects names to match exactly, beyond that I'd need a little more detail.

    I'd also consider moving to Mecanim which is a lot easier to switch models and animations.
     
  46. Dan_Tsukasa

    Dan_Tsukasa

    Joined:
    Jan 26, 2013
    Posts:
    155
    Perhaps I'll drop you an email beforehand to see if you'll be able to send me a working version if you have one.

    This evening I thought I'd give a shot at turning the current 2DToolkit version to use Raycast2D, but Nope, controller.CurrentDirection gives a bunch of errors about not existing, so there goes that particular idea, I thought I'd try that as Push Pull works in the current setup, its just using the normal Raycast Controller and not the 2D one, logic is that if I could switch that I'd be able to switch physics and be more or less where I wanted to be with it all.

    I don't know if it'd be faster and easier to get a Physics 2D Raycast 2D version of the 2DToolkit running (using toolkit animations instead of the unity ones that is).
     
  47. Kafar

    Kafar

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

    I sent to you a PM.
    Thanks in advance.

    -Kafar
     
  48. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    I don't see a PM...
     
  49. Kafar

    Kafar

    Joined:
    Nov 29, 2012
    Posts:
    220
    Sorry, email.

    -Kafar
     
  50. The_Daleatron

    The_Daleatron

    Joined:
    Nov 26, 2013
    Posts:
    43
    I thought that mite be it thanks.