Search Unity

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

[Released] 2D Platform Controller

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

  1. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    The sprite system is not intended for production use. It's just being added so I can include a fully playable and reasonably nice looking demo. You could probably use it in a simple game but as you say there are many much better solutions out there.

    As for integration the controller sends animation as events which can be plugged in to any 2D or 3D animation system pretty easily. I wrote some sample code for SmoothMoves in (literally) 2 minutes. Several people have said they added Uni2D and 2D Toolkit without issues.
     
  2. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Most of the adventure kit is not likely much use in a platform game, its made for point and click adventures... its also months from release.
     
  3. blaize

    blaize

    Joined:
    Jul 25, 2012
    Posts:
    41
    What's the planned release date for the second update? (your first post says the 25th)
     
  4. Player2D

    Player2D

    Joined:
    Feb 2, 2013
    Posts:
    50
    also interested
     
  5. parnell

    parnell

    Joined:
    Jan 14, 2009
    Posts:
    206
    Gotta say I'd be pumped for cutscenes, dialogue (tree?), and saving/loading. I'm not sure how the item interactions are handled.
    Would be cool to have them potentially work or at least allow the ability to work with the controller.

    Anyways, I'm off to GDC today, and will be picking this up this week for sure.
    Can't wait any longer!
    Thanks again and keep it up
    B
     
  6. robinball

    robinball

    Joined:
    Jan 1, 2013
    Posts:
    48
    I'd just like to add my support for an adventure inventory system. I started messing about with a point and click adventure prototype, but the inventory and object handling proved to be beyond my limited scripting abilities.
     
  7. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    A bug fix version was submitted last week, but it doesn't have new features. It does have instructions for using platform controller with Unity Touch Prefabs. I'll have to update the schedule a bit as the sprite based demo is aimed for the next release. It's also competing for time with the item system.
     
  8. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Dum de dah ... still waiting on update to be approved.
     
  9. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Update Approved and on the store.
     
  10. blaze

    blaze

    Joined:
    Dec 21, 2011
    Posts:
    211
    Awesome!
    What about a "jetpack physics"?
     
  11. blaze

    blaze

    Joined:
    Dec 21, 2011
    Posts:
    211
    The RobotSample is not working. Is it complete?
     
  12. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Argh that shouldn't be in this release! This release was a bug fix for horizontal movement, and a few wall jump bugs. Thats what I get for rushing the release.

    Jetpack physics will be in the RobotSample. I guess I have some good motivation to get it finished now.
     
    Last edited: Mar 28, 2013
  13. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Updated front page with new dates for updates.
     
  14. sefou

    sefou

    Joined:
    Aug 30, 2011
    Posts:
    287
    Great. Thanks. :)
     
  15. ProjectOne

    ProjectOne

    Joined:
    Aug 9, 2010
    Posts:
    442
    Excellent thanks
     
  16. maaboo

    maaboo

    Joined:
    Dec 26, 2012
    Posts:
    12
    Does anybody know how to do the strictly vertical falling (i mean as in the Lode Runner) and jumping. Can't think it out…
     
  17. parnell

    parnell

    Joined:
    Jan 14, 2009
    Posts:
    206
    Hi JohnnyA,

    For the climbing ledge stuff will that stuff be set up for a 3d character as well as the 2d? Also, do you need any animations for that?
    Let me know
    B
     
  18. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    You mean no ability to adjust position in the air? There might be a smarter way integrated into the raycast character controller (like a really high jump drag) but you could also just put a hardlock on the movement in the x value during character state jumping or falling or drop x Velocity in the air. You could also check isGrounded and when it comes up false whatever the current .x position lock to that value till isGrounded returns true again.
     
  19. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Fuzzy Slippers solutions are all on the mark.

    Code (csharp):
    1.  
    2. public class StragihtFall : MonoBehaviour {
    3.    
    4.     public RaycastCharacterController character;
    5.    
    6.     void Update () {
    7.         if (character.State == CharacterState.FALLING) character.SetDrag(9999);
    8.     }
    9. }
    10.  
    Will stop you moving while falling.

    Setting jump drag to 9999 will stop you moving while jumping.
     
  20. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    Hey JonnyA,

    So i am working wirh nGUI and made my Movement-Buttons for the Player wirh this plugin. How exactly can i tell , for wxample, left button to move your controller to the left? (Also moving it a bit with a single Tap and all the way till i release my finger)
     
  21. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    The simplest way would be to create an input controller which has x and y values but doesn't alter them in update.

    Code (csharp):
    1.  
    2. public YourSimpleInputController input;
    3. public float dir;      // What direction to move in (negative or positive for left/right).
    4. public float maxHold;  // Increase input value the longerwe hold the button, up to maxHold.
    5.  
    6. private float timer;
    7.  
    8. public void OnPress(bool pressed) {
    9.   if (pressed) {
    10.     if (timer < maxHold) {
    11.       timer+= Time.deltaTime;
    12.       if (timer > maxHold) timer = maxHold;
    13.     }
    14.     input.x = dir * timer;
    15.   } else {
    16.     timer = 0.0f;
    17.     input.x = 0.0f;
    18.   }
    19. }
    20.  
    I'm not near my Unity machine, so this is untested code. If you have trouble I'll be available (with Unity in front of me) in about 8 hours time to help.
     
  22. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Just a little bump as I finally have a rating in the asset star ... and its 5 Stars ... woot!

    On the other hand I've been a bit sidetracked so falling behind on the rope update. Really hoping I can get it done soon.

    - John A
     
  23. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    That reminded me I hadn't rated your asset either so take another 5 stars from me because this was a great value. What sort of rope / rope physics are being added? I've been piddling with adding ropes to my game but haven't gotten them working very well. Parenting / swinging is fine but the movement feels all wrong on the dismount so I can't really get a good 'swing' out of it.
     
  24. blaze

    blaze

    Joined:
    Dec 21, 2011
    Posts:
    211
    Yeah! Me too. I forgot to rate. And is a awesome and simple working controller.
    I dont know if is this kind of rope. If yes, I think that we will need to rate 6 stars, not 5.
     
  25. ZacCom-Corp

    ZacCom-Corp

    Joined:
    Apr 5, 2013
    Posts:
    10
    I have a question and can't figure it out. I use 2D toolkit to make my animated sprites and able to have the player work really good going right. However, I make the player go left and the player just backs up and doesn't turn to the left. Where in the code do i make the player flip to the left in your plugin? Also, great asset just need help on this one thing.
     
  26. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    @Fuzzy and Blaze - Thanks for the ratings much appreciated.

    With the ropes I plan on static, moving, swinging ropes (hold left/right to swing) but I'm actually having trouble finding good reference games. Anyone know of some platform games that have nice swinging rope behaviour? It's much easier to work from a reference!

    @ZaCom Corp - You shouldn't change the rotation of the controller, just the graphics/model. I haven't used 2D Toolkit but in most sprite libraries you can set the scale to negative to flip the images. Have a look at ModelController and you will see there is a check direction method that makes the character face the way they are moving. You might want to do something similar but instead adjust the scale:

    Code (csharp):
    1.  
    2.     private void CheckDirection(){
    3.         if (controller.Velocity.x > 0 ) {
    4.             transform.scale = new Vector3(1,1,1);
    5.         } else if (controller.Velocity.x < 0) {
    6.             transform.scale = new Vector3(-1,1,1);
    7.         }  
    8.     }
    9.  
    A more complex implementation might consider the direction the character is moving AND the direction the player is holding (so you can change the way you are facing whilst sliding in the other direction). However the above should get you started.
     
  27. blaze

    blaze

    Joined:
    Dec 21, 2011
    Posts:
    211
    Johnny, Limbo is the best reference to "real physics". The ropes are awesome, and it uses Box2D for the 2D physics. (https://code.google.com/p/box2d/)
    $Limbo-small-361.jpg

    Another reference, that I remember, is Circus Charlie (1986) for NES.
    $c453fe580d2adb5bdb80b76d9fac06b8.png

    Another one is Pitfall:
    http://goo.gl/VWC7H
    $pitfall_wide.jpg
     
  28. ZacCom-Corp

    ZacCom-Corp

    Joined:
    Apr 5, 2013
    Posts:
    10
    Thank you very much I didn't think about that my character is working flawlessly. Thanks again. 5 stars.
     
  29. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    In my game I'm trying to implement ropes like Trine. Not the best footage but you can see them used here:
    http://youtu.be/zqWdS1-pnMk

    I agree that Limbo rope physics are fantastic though.
     
  30. msbranin

    msbranin

    Joined:
    Jan 19, 2009
    Posts:
    104
    Would you mind sharing your animation controller script you use to get this platform controller working with 2D toolkit sprites and animations.I have tried and and tried and tried.
     
  31. ZacCom-Corp

    ZacCom-Corp

    Joined:
    Apr 5, 2013
    Posts:
    10
    Simple character input script is linked to the character. Then my animation script from 2d Toolkit (wip) is attach to the AnimatedSprite. child of the character. I call it Tutorial Anim Controller(script) Here the code still WIP but when you move the animation move then you need to tweek the animation speeds with movement speeds.

    Here the code.

    using System.Collections;

    public class TutorialAnimController : MonoBehaviour

    {
    virtual public float x{get; protected set;}

    /// <summary>
    /// The y movement. 1.0f = up, -1.0f = down.
    /// </summary>
    virtual public float y{get; protected set;}

    /// <summary>
    /// Is the jump button being held down.
    /// </summary>
    virtual public bool jumpButtonHeld{get; protected set;}

    /// <summary>
    /// Was the jump button pressed this frame.
    /// </summary>
    virtual public bool jumpButtonDown{get; protected set;}
    // Link to the animated sprite
    private tk2dAnimatedSprite anim;

    // State variable to see if the character is walking.
    private bool walking = false;

    // Use this for initialization
    void Start () {
    // This script must be attached to the sprite to work.
    anim = GetComponent<tk2dAnimatedSprite>();
    }

    // This is called once the hit animation has compelted playing
    // It returns to playing whatever animation was active before hit
    // was playing.
    void WalkCompleteDelegate(tk2dAnimatedSprite sprite, int clipId) {
    if (walking) {
    anim.Play("walk");
    }
    else {
    anim.Play("idle");
    }
    }



    // Update is called once per frame
    void Update () {
    // jumpButtonHeld = false;
    // jumpButtonDown = false;
    x = 0;
    y = 0;

    if (Input.GetKey(KeyCode.Space)) {
    // Only play the clip if it is not already playing.
    // Calling play will restart the clip if it is already playing.
    if (!anim.IsPlaying("jump")) {
    anim.Play("jump");

    // The delegate is used here to return to the previously
    // playing clip after the "hit" animation is done playing.
    // anim.animationCompleteDelegate = HitCompleteDelegate;
    }
    }

    if (Input.GetKey(KeyCode.D)) {
    if (!anim.IsPlaying("walk")) {

    // Walk is a looping animation
    // A looping animation never completes...
    anim.Play("walk");


    // We dont have any reason for detecting when it completes
    anim.animationCompleteDelegate = null;
    walking = true;



    }


    }
    if (Input.GetKey(KeyCode.A)) {
    if (!anim.IsPlaying("walk-l")) {

    // Walk is a looping animation
    // A looping animation never completes...
    anim.Play("walk-l");

    // We dont have any reason for detecting when it completes
    anim.animationCompleteDelegate = null;
    walking = true;
    }
    }
    if (Input.GetKey(KeyCode.W)) {
    if (!anim.IsPlaying("idle")) {
    anim.Play("idle");
    anim.animationCompleteDelegate = null;
    walking = false;
    }
    }
    }
    }
     
  32. Moraleidahgo

    Moraleidahgo

    Joined:
    Mar 3, 2012
    Posts:
    107
    How about trampolines? I think those would be a nice feature.
     
  33. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Falling behind schedule but ropes are almost done. Hopefully submit them tomorrow and will post a video here too.
     
  34. blaze

    blaze

    Joined:
    Dec 21, 2011
    Posts:
    211
    Awesome! Cant wait for it!
     
  35. rygaar

    rygaar

    Joined:
    Mar 28, 2009
    Posts:
    63
    Do you plan on mecanim support? If so, do you have an ETA?

    cheers
     
  36. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Animation controllers are pretty simple to write, the only thing stopping me doing Mecanim is lack of mecanim based characters/animations. However I know theres plenty available for free, so there should be nothing stopping me. I'll pencil that in for the update after next (3 weeks or so).
     
  37. blaze

    blaze

    Joined:
    Dec 21, 2011
    Posts:
    211
    Any news?
     
  38. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Hey Blaze, ropes are still almost done. All the functionality is there, but just ironing out the bugs, I don't want to release them if they aren't rock solid.
     
  39. sirius_002

    sirius_002

    Joined:
    Aug 16, 2012
    Posts:
    65
    I don't think ropes are supposed to be "rock solid" though, hehe. Can't wait Johnny :)
     
  40. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Still not quite there but getting closer. Please check out the demo here:

    jnamobile.com/samples/RopeSample.html

    Controls: Arrows keys and SPACE, R to restart.

    Its showing non-climbable fixed ropes and climbable flexible ropes. You can also create non-climbable flexible ropes and climbable fixed ropes. Lots of settings to tweak how your character jumps on and off ropes etc.

    Things that aren't quite right:

    - If jump at the peak the rope has no velocity so you dont go as far as jumping at around 3/4 of the peak. This is physically accurate, but doesn't feel right.

    - The snap to middle is too abrupt.

    - Its hard to build your own ropes (more complex than ladders), and also takes time to get them to feel right. I will provide many prefabs, but do I need an editor tool?

    Please let me know your thoughts.

    - John A
     
  41. Mars91

    Mars91

    Joined:
    Mar 6, 2012
    Posts:
    572
    PM sent
     
  42. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    PM Answered ;)

    PS guys link on previous page to rope sample.
     
  43. blaze

    blaze

    Joined:
    Dec 21, 2011
    Posts:
    211
    Awesome ropes!
    An Editor Tool is not required, just a good PDF and Video tutorial.
    I loved the ropes. There is a state, to know to what side the player is facing?
    In the "not rigid" rope, I can add more "nodes"? Just to make it more malleable?
     
  44. JohnnyA

    JohnnyA

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

    seems most people are happy with the ropes (even if I am not) so I will package them up for release soon. I think maybe they are just good enough, but I can always improve in future updates.

    The ropes work just like a ladder in that you add as many control pieces as you want. The complexity is unlike a ladder you need a joint piece and a step piece, so its a bit more work to build them. It also needs a top level controller object to coordinate it all. I might start with a video, and then look at an editor tool for a future update.

    In terms of making more malleable, the physics of the rope is Unity hinge joints (fix joints also work). You can add as many as you want, although you do need to be a little careful of the settings. If your player gets close to horizontal I don't think the controller would be able to handle it.

    Theres no animation event, as the rope controller not the player controller handles movement. However you can inspect the rope controller to get the last direction the player swung in:

    Code (csharp):
    1.  
    2. if (character.Parent is Rope) {
    3.   float swingDir = ((Rope)ccharacter.Parent).controller.lastSwingDirection;
    4. }
    5.  
    You will also notice a lot more power is given to platforms with this update. They can (if they want) completely override player movement. This makes complex platforms much easier to build.

    Regards,

    John A
     
  45. sefou

    sefou

    Joined:
    Aug 30, 2011
    Posts:
    287
    Hi JohnA,
    awsome rope . Just one request : edge hanging ?

    Thanks.
     
  46. parnell

    parnell

    Joined:
    Jan 14, 2009
    Posts:
    206
    Soooo i dont have internet for my computer (just my phone). Any chance you could post a youtube video of the rope in action?
    Thanks!
    B

    ps i too am cant wait to hear about edge hanging.
     
  47. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Here's a video:

    [video=youtube_share;gJBTbZxw35I]http://youtu.be/gJBTbZxw35I 95%
     
  48. Player2D

    Player2D

    Joined:
    Feb 2, 2013
    Posts:
    50
    Hi JohnnyA.
    there is a demo touch control (ios, android)?
     
  49. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Included is instructions for using with Unitys touch controls. Several people have also used with various asset store touch control packages.

    I'm planning on setting up a touch demo, I just need Unity to confirm I can use their standard assets in my package.

    - John A
     
  50. blaze

    blaze

    Joined:
    Dec 21, 2011
    Posts:
    211
    In the end of this video, this other video came to me like a suggestion. Take a look: