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

[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,039
    If you do a google search with:

    site:http://forum.unity3d.com/threads/173640-Released-2D-Platform-Controller/ <<YOUR SEARCH HERE>>

    it searches just this thread... you might need to also click "repeat the search with the omitted results included"
     
  2. MBoffin

    MBoffin

    Joined:
    Mar 29, 2013
    Posts:
    15
    I had no idea you could add anything after the domain on a "site:" search (other than the keywords, of course). TIL. Thanks!
     
  3. MBoffin

    MBoffin

    Joined:
    Mar 29, 2013
    Posts:
    15
    Okay, now I have a real question. I'm trying to implement passthrough platforms, but I'm running into an issue where the RaycastCharacterController ends up "hopping" up through the platform once they are halfway up through the platform. (Rather than waiting until the feet pass the top of the platform.) Anyone else experience this, or am I just setting up the controller wrong?

    Just for visuals, the attached image shows the layer I'm setting as the "pass through layer". (The bright, un-dimmed part is part of the "pass through layer".)

    $passthrough.png
     
  4. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Been a while since I looked at that code but as I remember what happens with passthrough is that if you only stand on them if you are moving downwards. If you had a large collider and your jump finishes mid platform, you would snap to the top.

    This should be fixed by having a thin collider on your passthrough platform (there's no need to fill the whole box as you can pass through it). You could also address it by reducing the length of your feet colliders, although this has its own ramifications (see notes in code/doco on terminal velocity).

    Note that I'm writing this without reference to project/code, if it doesn't address the issue let me know and I'll take a look with the code in front of me.
     
  5. MBoffin

    MBoffin

    Joined:
    Mar 29, 2013
    Posts:
    15
    I actually had that same thought and tried that. Unfortunately, if the controller's jump hits its peak while it is midway through the one-way platform, it still pops the controller onto the top. I made a .gif so you can see (the dark gray strips are the thing one-way platforms)....

    $passthrough-glitch.gif
     
  6. MBoffin

    MBoffin

    Joined:
    Mar 29, 2013
    Posts:
    15
    I did some more fine-tuned testing and I see what's happening. Once the side raycasters are past the top of the platform, it is ending the jump (you can see it go to "idle" in the above .gif actually), and then once it's out of the jump, that's when it hops on top of the platform. Still not sure how to prevent this. :\
     
  7. MBoffin

    MBoffin

    Joined:
    Mar 29, 2013
    Posts:
    15
    Here's another example, but this time using the BasicSample that comes with 2D Platform Controller. If you get on the block under the one-way platform and set your BasicCharacter's jump velocity to 10.71 and then jump, you will see the behavior I'm talking about. (I'm using BasicSample, as it's a common baseline you can use to test yourself.)

     
    Last edited: Sep 25, 2013
  8. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Edit removed this solution
     
    Last edited: Sep 25, 2013
  9. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    EDIT REMOVED SOLUTION

    The posted solution is not really suitable for go live.

    This snap is always possible if you get a performance hiccup. The problem with the passthrough is that you see the problem all the time even without a performance hiccup.

    Level design should (at least partially) solve this too... don't put your platforms at a height where the jump comes to just below them. If you think about this you will need to do it anyways as if the jump doesn't quite make the height then you only have two options: miss the platform or snap (or some kind of smooth lerping snap which is what I might do).

    In the short term decrease your feet colliders as much as your maxFrameTime allows and put your platforms at a height that makes sense.

    Anyways I'll have a think about a better solution and hopefully get something in the next minor update.
     
    Last edited: Sep 25, 2013
  10. MBoffin

    MBoffin

    Joined:
    Mar 29, 2013
    Posts:
    15
    In just some raw, quick testing, this seemed to fix it! Thanks! :D

    In having read through a lot of this thread, I've noticed you're very active in responding to questions and so forth. Just want to make sure you know it's very, very much appreciated. This is definitely a package I'd recommend to others doing platformers.
     
  11. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Sorry mate, I removed the solution as it creates other issues (missing platforms). Decreasing feet distance should get you a long way there (as long as you ensure you set the terminalVelocity and maxFrameTime correctly too), and I am messing with some other ideas right now. Will let you know how I go.
     
  12. MBoffin

    MBoffin

    Joined:
    Mar 29, 2013
    Posts:
    15
    No problem. I still appreciate you working on the problem. My dev partner and I agreed that level design will help minimize this problem for the most part, so we're going to go with that until there's a better solution. Thanks again! :)
     
  13. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    I have a solution that seems reasonable and quite simple. If you are moving through a passthrough platform, gravity will not be applied. As long as your feet colliders aren't too large this should remove visible snaps... if you are right on the limit of a platform you will just float that tiny bit extra.

    Still testing, but send me a PM/email if you want the code.
     
  14. push_over

    push_over

    Joined:
    Aug 1, 2013
    Posts:
    1
    Just wanted to say that this is one of the best packages I've used. It's well documented, the code is clean and well commented, and it's incredibly easy to customize and hack for whatever specific needs one may have. The only issue I've had so far with it was regarding frametime. I felt like everything the character did was rather sluggish and slow, especially the rate at which gravity was applied. I tried adding a simple gravity multiplier (that is, frametime * gravity * gravityMultiplier) and cranking up all the values for runspeed, walkspeed, etc. It just didn't feel right, and the only way I've found to get everything feeling right is by doing something that I feel is kind of a messy hack:

    This seems to speed everything up in a very smooth, desirable (for me) way. However, I'm curious if there is a cleaner/better way of going about this?
     
  15. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Increase:

    Movement.walkSpeed/RunSpeed
    Physics.Gravity
    Movement.acceleration
    Jump.Velocity
    (and possibly Movement.TerminalVelocity if you aren't falling fast enough).

    Alternatively you can always tweak timescale directly (time settings in Unity.)

    ----

    That said that frametime adjustment might be a nice idea as a way to allow speed up without having to either a) edit multiple variables or b) adjust timescale and thus potentially affect other packages. I might look at adding it as a public static on the character class

    The only issue I can see is you would need to adjust terminal velocity accordingly to ensure don't fall through platforms (if you can move 5 times further in a frame then terminal velocity will have to be a lot smaller).
     
    Last edited: Sep 27, 2013
  16. Dan_Tsukasa

    Dan_Tsukasa

    Joined:
    Jan 26, 2013
    Posts:
    155
    A common issue I run into (and it also seems to happen to a few others), is the collision Matrix and setting it up correctly.

    Johnny would it be possible to post a screenshot of your collision matrix, from a project where push/pull, physics, rope climbing, ladders, hit boxes and even enemies are all working perfectly together.

    I generally get things working, but then I add an enemy, or I add something new and realize that my current setup is pretty inefficient in all honestly and I go to fix it, only to have the same issue again when I later add something else, of course its simply me being a bit of a moron but It'd be great if you could post a screenshot of the above mentioned collision matrix, might save quite a few people some headaches in the future.

    Sorry if it sounds like a silly request.

    EDIT: Additionally, have you ever considered integrating the controller with Spriter (a skeletal 2D animator/framework that also has a unity plugin), I suppose you could say its somewhat like SmoothMoves (though I've not used SM so I can't really comment).
     
    Last edited: Sep 27, 2013
  17. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    The picture in the manual on page 15 is pretty much what I use, if you are unsure the rule of thumb is don't include a collision if you don't need it.
     
  18. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Just submitted v1.7.2.

    None of the big updates yet, but a lot of small movement updates that are quite handy :)

    heres the release notes:

    Code (csharp):
    1.  
    2. v1.7.2 Movement Updates
    3.  
    4. - New movement styles in X direction
    5.     PHYSICS_LIKE,  // Uses acceleration and drag to give a physics like movement style (how it used to work).
    6.     DIGITAL,       // Pressing a direction immediately changes speed to walk/run speed. NO accerlation or sliding.
    7.     DIGITAL_WITH_SLIDE   // As above but character still slides to a halt.
    8.  
    9. - Ledge Hang in Facing Direction only
    10.  
    11. - No gravity while moving through passthrough platform
    12.     * helps reduce "snapping"
    13.  
    14. - Drag not applied while holding down left/right
    15.     * Fixes issue with high acceleration with slow frame rate
    16.     * UPGRADING USERS NOTE: You may need to slighlty reduce your acceleration
    17.  
    I've also started to look at swimming.
     
    Last edited: Sep 28, 2013
  19. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    Hi Johnny,

    I'm trying to trigger a jump with a tap event, but the event itself is a 'tap', not a touchstart and touchend. So when I try and set jumpButtonDown to true, and in Update set it to false, the character won't jump. (I presume it's being set to false before the engine is picking it up.) The workaround I found was this:

    Code (csharp):
    1.  
    2. if(cycle == 0){
    3.     cycle++;   
    4. } else if (cycle == 1){
    5.     jumpButtonDown = false;
    6.     cycle = -1;
    7. }
    8.  
    So I ensure it goes through one Update cycle before resetting it, but I'm wondering if there's a cleaner solution?

    Thanks in advance!
     
  20. lightassassin

    lightassassin

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

    Been working my butt off for the comp, even took time off the day job to complete ;) Just wondering if I could somehow get a copy of the update without waiting for the asset store to process. Or at the very least a copy of the updates to the direction facing. I hacked together something myself, but just paranoid now in case of anything I missed.

    If not it's okay and I hope you've done well with your entry =) Once I've updated my site etc.. I'll drop you some links (naturally you're in the credits, appreciate the work, I really do) so you can see what I've done, I've got some screenshots of how things have progressed over the last couple months. So hopefully I can champion your asset a bit and you can get some more sales.

    Anyway, back to work, got a few things to go over (sound guy flaked... the whole game is now a solo effort). Finish up a few things and submit. Already got another 3 games planned using your pack, going to turn it into a series. So keep up the excellent work =)

    Cheers,
    Ben
     
  21. Xaikira

    Xaikira

    Joined:
    Jul 24, 2013
    Posts:
    8
    Worked perfectly man, big thanks!
     
  22. GreyEyedBeast

    GreyEyedBeast

    Joined:
    Jan 6, 2013
    Posts:
    7
    So I have a bit of a strange issue. My project takes advantage of tk2d sprite system but uses the 3d animation pipeline. I am looking to create a type of hybrid Animator script that will still use the mirroring mechanic from the alien animator in combination with the regular animation of the Hero animator. I have a pretty limited scripting knowlege so if anyone could highlight the pieces I need from the alien script and what it should replace on the Hero that would be awesome!. If not ill keep trying to stumble through it myself :D

    Thanks in advance!
     
  23. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    It sounds like a script execution order issue. The movement scripts operate in LateUpdate, so usually you can set to false in Update with no problem as long as you set to true *after* this. The key would be when it is getting set to true... when/how is your "tap event" triggered?
     
  24. JohnnyA

    JohnnyA

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

    I ended up cancelling my windows comp entry, it was impacting the timeline of another project, but good luck with yours!

    If you send me an email with your order number I'll send you the updated package.

    - John A
     
  25. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Anything then changes character rotation should in Hero Animator should be replaced with a change of scale (or removed in the case of things like climbing where the Hero animator faces the character with its back to the camera).
     
  26. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    I'm using Finger Gestures (http://fingergestures.fatalfrog.com/) in which 'Tap' fires a global FSM event in Playmaker. The controller manager listens for it, and once it hears it triggers my 'SendJump()' function. Which sets the value. To be honest I'm not sure at what stage in the cycle Playmaker event listeners fire? Don't suppose you have any idea?
     
  27. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Nope, you should be able to debug it and see when it gets called though.

    That said I wouldn't worry too much about it if its working :)
     
  28. eedok

    eedok

    Joined:
    Sep 21, 2009
    Posts:
    194
    just downloaded and imported the package and have a quick gripe, you have this style code in a few places:
    Code (csharp):
    1.  
    2. #if UNITY_4_0 || UNITY_4_1
    3.     visibleContents.SetActive(true);
    4. #else
    5.     visibleContents.SetActiveRecursively(true);
    6. #endif
    7.  
    so being on Unity_4_2 this gives me warnings about obsolescence, but your package requires Unity 3.5 as a minimum, so the else in that statement is only valid for one version of Unity that your package support so why not do the defines the other way like this?

    Code (csharp):
    1.  
    2. #if UNITY_3_5
    3.     visibleContents.SetActiveRecursively(false);
    4. #else
    5.     visibleContents.SetActive(false);
    6. #endif
    7.  
     
  29. GattsGK

    GattsGK

    Joined:
    May 5, 2013
    Posts:
    18
    Hello!

    First of all, great asset!

    I am extending the controller in order to add new actions (not only new animations) like shooting. The thing is that I don't see how to update the character state without modifying the asset core classes. First of all, I have created a new class that extends RaycastCharacterController (lets call it NewCharacterController). The new actions are analyzed in the Update method of the NewCharacterController class, that is executed before the LateUpdate of RaycastCharacterController. But I can't change the state, because it is changed again inside the second method. And if I want to combine the new actions with the current ones, for example shoot while walking, do I have to modify the method MoveInXDirection or there is some workaround I haven't seen?

    So the question should be, is there any way for adding new custom actions without changing (too much) the given controller? I am talking just about the controller, not the iput or animation classes.

    Many thanks!
     
  30. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    @eedok Sure thing, it's probably that way because to support 3.5 I do all the dev in 3.5 and thus in mind its the other versions that are the exception not the rule.
     
  31. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Particularly if you want to combine the motions it doesn't seem like they are part of the characters movement state. If its something like shooting then I usually write a custom animator (to show the attack) and a custom input (to override motion during the attack). If you had recoil you could override the input and also apply a velocity to affect the characters movement. And if you have some very specific/complex thing you want to do you can always deactivate the controller temporarily.
     
  32. Roidz99

    Roidz99

    Joined:
    Jul 8, 2010
    Posts:
    198
    hey Johnny,

    Any progress yet on the mecanim controller or does this have less priority ?
     
  33. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    It's the highest priority major update, the other changes were minor features/bug requests.

    That said I'm aware its been a long time coming, I might do an initial release which has core behaviours set up with Mecanim (but no IK). Effectively a slighlty extended and cleaned up version of the WIP mecanim controller I have been sending to people.
     
  34. Roidz99

    Roidz99

    Joined:
    Jul 8, 2010
    Posts:
    198
    awesome !
     
  35. AMO_Noot

    AMO_Noot

    Joined:
    Aug 14, 2012
    Posts:
    431
    Woo! =D
     
  36. Fabian Schempp

    Fabian Schempp

    Joined:
    Jun 1, 2013
    Posts:
    17
    Hi Everybody,
    I have a small 2DPlatformController related problem and hope someone can help me.

    If the character jumps to one of the ladders (the new ladder system) it takes about 1-2 seconds until he sticks to them, and goes to the climbing state which is a bit to long. Is there something i can do to shorten that time?
     
  37. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Need a little more info... there's no delay as such on autostick but in the latest ladder update the character wont stick whilst still moving upwards. Is that what your issue is?

    A temporary fix for this would be to update the line that reads:

    if ((velocity.y <= 0.0f || startedClimbing || climbing.autoStick) ledgeDropTimer <= 0.0f) {

    and change it to

    if ((velocity.y <= 0.0f || startedClimbing || climbing.autoStick) ledgeDropTimer <= 0.0f) {

    You may also need to reduce the jumpButtonTime a little bit as the defaults are fairly high.

    Let me know if this is not your issue. :)
     
  38. Fabian Schempp

    Fabian Schempp

    Joined:
    Jun 1, 2013
    Posts:
    17
    Hi Johnny
    Thanx for the quick reply.
    I double checked but the delay is about 1 second while the character is already falling down. Any idea what could cause this?
     
  39. Mad_Fox

    Mad_Fox

    Joined:
    May 27, 2013
    Posts:
    49
    Hi johnny, quick question here, im trying to do something basic like this:

    but im having problems with the collisions, i have a similar setup like your mario sample, and i've made a quick rope/boulder thing to test, in the rope i have the rotaing script and nothin more, and the boulder (its a cube) its parented to the bottom of the rope with a rigid body and the kill box script, the problem is that this works sometimes, and sometime it just past trough, if i unparent the boulder and leave it there, it kills the character everytime that touch it, the problem is when its moving. Can you help me with that? thanks!
     
  40. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Can you send me your project (use the support email from the instructions)?
     
  41. Dan_Tsukasa

    Dan_Tsukasa

    Joined:
    Jan 26, 2013
    Posts:
    155
    Mad_Fox, I'd recommend simply having an animated swinging pendulum instead of trying a complex physics based rope solution to it, you're making it a lot more complicated than it needs to be, meaning than when you hit an issue like this, it takes a lot longer to fix.

    I say animate it in some 3D software, give it a hitbox and import it, then you've only got an animation playing, which is a lot less going on than an object with a dynamic rope + swinging physics + other things.

    Sorry, Its not really my place to make suggestions as its Johhnys thread, but this seems a little overkill for such a simple puzzle.

    Also, what game is that gif from?
     
  42. Mad_Fox

    Mad_Fox

    Joined:
    May 27, 2013
    Posts:
    49
    Dan, im 3d modeler and i know just a little of coding, i swear i didnt know how to do rope physics or anything like that, my example is far more simple, just a cube stretched with a javascript that rotate this cube/rope (just a "transform.rotate"), and a box/boulder with a hitbox parented to the bottom of the other box/rope.
    Im gonna try making the animation in a 3d software with a collider and a hitbox,
    Thanks anyway Dan!

    PS: that gif is from the android game "manuganu"
     
  43. Dan_Tsukasa

    Dan_Tsukasa

    Joined:
    Jan 26, 2013
    Posts:
    155
    Oh When I said Rope Physics I meant the ropes from this 2D Platformer kit, I assumed you were using the ropes from this.
    Sorry then, my assumption was wrong.

    I'm also a 3D Artist by trade, snap! Good luck with this.
     
  44. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    It's actually easier for me and better for everyone if everyone is making suggestions :)

    ----

    As to your issue Mad_Fox... the damage scripts are based on normal Unity colliders/triggers. Are you sure Unity is registering a collision? Maybe you could debug or add a log statement to make sure the collision method is getting triggered.
     
  45. FlyinWhee

    FlyinWhee

    Joined:
    Jun 3, 2013
    Posts:
    4
    Bit of a weird issue happening here. I have a script that causes the whole world geometry to turn around the player, in order to make the player move around the 3D space in a few selected areas.

    But when that script runs, all objects that have a script inherited from "platform.cs" that are in the "world geometry" hierarchy have their position.x and position.z moving a tiny bit forever after that. Those are the values affected by the script (that plus rotation around the y axis). If I simply disable the platform script from the inspector when that happens the movement stops, and restarts if I re-enable said script. No other objects are affected by that weird bug.

    Anything relevant someone could point me to, to help me fix this? Thanks.

    edit: I uploaded the test area, with the position values printing at the bottom of the screen to help illustrate what is going on. If you keep moving to the right, you will see a blue block on the ground, that's the platform sending that data. If you look at it closely, you'll see it moving, going to the left.

    Here's the link: http://bonincraft.x10host.com/webdev/Unity/platforms_rotatebug/platforms_rotatebug.html
     
    Last edited: Oct 2, 2013
  46. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Unity has various bugs when you rotate objects that have non-uniform scale. I expect your problem is to do with this.

    They are generally more apparent if you transform the rotated object or its children. If most of your platforms don't move you could remove the translation from them and just add it back to the platfoms sub-classes that do move.

    Alternaitvely you could add a condition so that the you only execute the translation if the platforms velocity is non-zero.
     
  47. FlyinWhee

    FlyinWhee

    Joined:
    Jun 3, 2013
    Posts:
    4
    Sounds like a good lead, I'll try working that angle and let you know how it goes.

    Thanks!
     
  48. Fabian Schempp

    Fabian Schempp

    Joined:
    Jun 1, 2013
    Posts:
    17
    I send you an e-mail.
     
  49. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Replied via email.
     
  50. RandAlThor

    RandAlThor

    Joined:
    Dec 2, 2007
    Posts:
    1,293
    When i bought this i thought i will get a realy good 2D platform controller wich it is but i also thought i will get something more complete at least after a while when i first read what you want to make with this kit.

    I see here something that happened with other kits too and that is frustrating me.

    When i bought it i thought i can make nice 2D platform games with it and i only have to wait a little but now you make some more other assets and this kit here slows down so much so i still can not make my 2D game with it after so many month.

    I do not expect to get a make my game button (there is a lot to do besides coding) but this is missing so much things that i think i as as a non coder can not make my game and i waste my money and time. I mean i waited month now and you have the nice what do you want list and what is ready but realy nothing besides your great support is happening here and with other unity asset store kits to. They just jumps to ther idears and left the buyers in the dust with there hopes on features.

    Please do not take it to personal because i like your 2DPC and your support but i spend so much money on different kits that mostly hang there now and and do not have it ready to use it in a real project once again as a non coder. I am sure yours and others will be used but they have someone to do the rest main things.