Search Unity

[Released] 2D Platform Controller

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

  1. BranDino

    BranDino

    Joined:
    Apr 12, 2013
    Posts:
    16
    {Rope Translation Solved!}
    Thanks for the suggestion I got in there and messed around a bit and I got it to work, by increasing the size of the 3 (Step) colliders per mesh, so that there was virtually no space between them and I got smooth vertical transition per rope link and between the links.... it seems that the Box collider around the (rope link) Mesh itself was creating the issue or telling the raycast controller it had reached the end of the rope and it stopped so I disabled the rope link collider...
     
  2. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,681
    Hmm that collider should be in a different layer... one not used by the controller.

    EDIT: Although I guess there is no need for that collider anyway, rope physics use joints so shouldn't need a collider ... thanks for the pointer :)
     
  3. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,681
    PS In case you missed it, the latest version with 2D Toolkit demo is out now :)
     
  4. SlashMeow

    SlashMeow

    Joined:
    Jul 23, 2013
    Posts:
    1
    First off: This package is absolutely amazing, JohnnyA. Great work.

    2 questions:

    1.) I remember reading somewhere that you were looking into making this package Mecanim compatible. Any update on that?
    2.) Is there any chance that you're looking into adding a Grappling Hook type of feature? I purchased Mr. Moustache Jump and Run and instantly fell in love with that feature for platforming.

    Thank you so much for your time.
     
  5. parnell

    parnell

    Joined:
    Jan 14, 2009
    Posts:
    206
    Great news!
    I noticed push/pull anims are in, but I don't see the settings or info for it. That coming later?
    Thanks!
    B
     
  6. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,681
    1. I have a working mecanim sample, it just needs some more animations and clean-up. Hopefully within the next few weeks.

    2. Definitely a possibility although exactly when I am not sure.
     
  7. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,681
    Hey mate, just a few bugs that need to be cleaned up for that, probably out within a week or two.
     
  8. sirius_002

    sirius_002

    Joined:
    Aug 16, 2012
    Posts:
    65
    Hi Johnny right now you can fall through platforms by pressing down, how can I change this to the classic down and jump?
     
  9. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,681
    Add an additional condition to the passthrough platform (character.characterInput.jumpButtonDown):

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class PassthroughPlatform : Platform {
    6.    
    7.     public float fallThroughTime = 1.5f;
    8.    
    9.     override public void DoAction(RaycastCollider collider, RaycastCharacterController character) {
    10.         if (collider.direction == RC_Direction.DOWN  character.characterInput.y < 0.0f  character.characterInput.jumpButtonDown) {
    11.             character.FallThroughTimer = fallThroughTime;
    12.         }
    13.     }
    14. }
    15.  
     
  10. sirius_002

    sirius_002

    Joined:
    Aug 16, 2012
    Posts:
    65
    Thanks buddy, you rock!
     
  11. Bast I

    Bast I

    Joined:
    May 28, 2013
    Posts:
    18
    Hi JohnnyA,

    thanks for your suggestion -- it worked perfectly -- and for the licensing clear-up!

    I totally second that! But I am willing to wait and/or pay for it. (But it wouldn't be too much hassle, would it? It is basically a lot like the rope swinging that is already implemented, right? Anyway, I would love to see it at some point.)

    Bast I
     
  12. sirius_002

    sirius_002

    Joined:
    Aug 16, 2012
    Posts:
    65
    This works great, but the character does a full jump before passing through the platform, while he should jump up just a little, like 10% of a full jump. Any ideas? Thanks!
     
  13. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,681
    Set the character.characterInput.jumpButtonDown to false once you "consume" it and then manually add a bit of velocity:

    Code (csharp):
    1.  
    2.     using UnityEngine;
    3.     using System.Collections;
    4.      
    5.     public class PassthroughPlatform : Platform {
    6.        
    7.         public float fallThroughTime = 1.5f;
    8.        
    9.         override public void DoAction(RaycastCollider collider, RaycastCharacterController character) {
    10.             if (collider.direction == RC_Direction.DOWN  character.characterInput.y < 0.0f  character.characterInput.jumpButtonDown) {
    11.                character.characterInput.jumpButtonDown = false;
    12.                character.Velocity = new Vector2(0.0f, 5.0f); // You might want to make this a variable, and play with different numbers that suit your gravity
    13.                character.FallThroughTimer = fallThroughTime;
    14.             }
    15.         }
    16.     }
    17.  
    Note that I'm not in front of Unity so that may not work :)
     
  14. sirius_002

    sirius_002

    Joined:
    Aug 16, 2012
    Posts:
    65
    Very cool, gonna try this tonight, many thanks!
     
  15. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,681
    No probs, let me know how it goes.
     
  16. sirius_002

    sirius_002

    Joined:
    Aug 16, 2012
    Posts:
    65
    As you suspected I sadly did receive an error:

    "Assets/2DPlatformController/Scripts/Platforms/PassthroughPlatform.cs(19,41): error CS0272: The property or indexer `RaycastCharacterInput.jumpButtonDown' cannot be used in this context because the set accessor is inaccessible".

    I'm not sure what it means, but you more than likely do.
     
  17. Xaikira

    Xaikira

    Joined:
    Jul 24, 2013
    Posts:
    8
    Got your plugin and absolutely love it. I'm currently developing a 2D game and trying to incorporate parallax background layers. I have a script that just uses basic inputs to move the layers by the given speed for that layer but if the player continues to walk into a wall the parallax layers keep moving. I'm still fairly new to this stuff and was wondering if I can detect a wall by referencing the side colliders somehow?
     
  18. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,681
    sirius You will need to add a method to your input class that handles setting jump button down to false (seems the default is readonly).
     
  19. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,681
    Xaikira you could but its probably easier to do your parallax scrolling relative to the camera movement (so every time the camera moves x your background move x * k (where k is some constant)).

    With your current scenario you could try using character.velocity.x .... but it will also stop scrolling when the player stops moving which is not exactly what you described.
     
  20. sirius_002

    sirius_002

    Joined:
    Aug 16, 2012
    Posts:
    65
    Hi Johnny, I did not make my own scene yet, just tested it on your "RopeSample.unity" and changed the script on "EnhancedPassthroughPlatform" and came up with the error. So it's using your "SimpleCharacterInput", thanks.
     
  21. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,681
    Yeah for changes to input you usually need to edit that class, think of anything outside the "plugins" directory as a sample. However if you are not a coder I can set it up for you no problems, I'll be doing some more updating over the weekend.

    Cheers,

    John A
     
  22. SullyTheStrange

    SullyTheStrange

    Joined:
    May 17, 2013
    Posts:
    147
    Hey Johnny,

    I tried scaling part of the Basic Sample scene from 1 to 100 since that's the size my game is, but the character behavior is flipping out on me. I tried to update the numbers for the new size including the raycast colliders, but clearly something's wrong. I uploaded my modified BasicSample scene if you could take a look:
    https://dl.dropboxusercontent.com/u/19702035/BasicSample2.unity (hopefully it works if I just send the scene?)

    What do I have to do to get it working at that scale? Oddly, it doesn't flip out if you land and then jump before you move, not sure what that means...
     
  23. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,681
    Sully as with Unity physics there is an assumption that 1 unit = 1m, and although you can work at larger scales, you need to scale all the variables up accordingly. Quite simply there's a LOT of variables and if you miss one key one it might behave oddly. I'll have a look through your scene and see if I can see anything that looks out of place.

    - John A
     
  24. sirius_002

    sirius_002

    Joined:
    Aug 16, 2012
    Posts:
    65
    Hi Johnny, I'm definitely not a coder, I'm a Playmaker/2d Toolkit user and I strongly depend on your asset to help me make my game. If you would, please set it up for me.
     
  25. SullyTheStrange

    SullyTheStrange

    Joined:
    May 17, 2013
    Posts:
    147
    Thanks Johnny, I already scaled up the exposed variables, and the only other one I could find in the script was the gravity.

    I have another (hopefully quicker!) question, what part of the script handles the slope movement? Not the "rotate to match the slope angle" part, but the "apply 'horizontal' velocity along that new angle" part. I've been dissecting the raycast character controller to combine it with my own script, and that's the only thing I can't get working (outside of the scale issue). I can get my character to rotate properly, but he still moves left and right as if he's on a flat surface instead of up the slope.
     
  26. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,681
    Hi Sully, thats not part of the controller at this point, its been suggested once or twice but fallen by the wayside due to other requests (I really need to create a bug/feature tracker) . Of course you can still implement this by attaching a simple script which adjusts drag/velocity (both exposed as properties) based on angle.

    EDIT: Also it wont work if you just send the scene ... export a custom package.
     
    Last edited: Jul 26, 2013
  27. SullyTheStrange

    SullyTheStrange

    Joined:
    May 17, 2013
    Posts:
    147
    Not sure I understand, if it's not part of the controller than how does it walk up slopes? :p That's all I'm asking basically. What part of the script makes it walk UP the slope instead of just phasing through it? That's what my own custom character is doing, it rotates to the proper angle when it hits a slope but it doesn't walk up the slope, it keeps going horizontally and passes through it.

    Also, what do I include in the custom package? Just the scene? Oh and I basically won't need to send it if I can figure out the other question. That's the only reason I needed to scale up your scene anyway, to try to replicate the slope movement.
     
  28. Dan_Tsukasa

    Dan_Tsukasa

    Joined:
    Jan 26, 2013
    Posts:
    156
    This isn't really a 'bug' of any sort, more something unusual, I can sit in unity for a good 8 hours and this issue never pops up, but when I boot up the project it does:
    Assets/2DPlatformController/Scripts/ExtraFeatures/Enemies/EnemyBounceAndFall.cs(34,29): error CS0122: `RaycastCharacterController.stunTimer' is inaccessible due to its protection level

    I'm still a beginner in c# in unity (had been using JS until now), and I know its an issue of private and public voids, and from my understanding, unless you specify public, all 'void's (sounds weird to say that) are automatically set to private, unlike in JavaScript where they're set to public.

    However simply changing it to a public void like so: Doesn't actually fix the issue, I'll look about and see if I can work it out, but perhaps this is something you're fixing anyway (if its even an issue or just me).

    Code (csharp):
    1.  
    2.     public void LateUpdate () {
    3.         if (controllerActive) {
    4.             frameTime = RaycastCharacterController.FrameTime;
    5.             bool grounded = IsGrounded(groundedLookAhead);
    6.             if (stunTimer > 0 ) {
    7.                 stunTimer -= frameTime;
    8.                 ForceSetCharacterState(CharacterState.STUNNED);
    9.             } else {
    10.                 MoveInXDirection(grounded);
    11.             }
    12.             MoveInYDirection(grounded);
    13.         }
    14.         UpdateAnimation();
    15.     }
    16.  
     
  29. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,681
    Hey guys I've added a feature request page:

    http://jnamobile.com/featurerequests

    You need to contact me (via PM or email) to get a feature added to the list, but you can vote on them anonymously.

    Cheers,

    John A
     
  30. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,681
    Don't make that change, LateUpdate is a unity method (like Update) and should not be public. The void part has nothing to do with the access modifier (its the return type). In c# if you don't specify an access modifier it is by default internal which means it can be access from the same assembly.

    Anyways, to fix that issue find stunTimer in the RaycastCharacterController and make it protected instead of private.

    - John A
     
  31. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,681
    The character transforms for X are applied in relative space not world space. So when the character is rotated moving in X moves parallel to the slope.
     
  32. SullyTheStrange

    SullyTheStrange

    Joined:
    May 17, 2013
    Posts:
    147
    That's what I thought, the issue turned out to be elsewhere. I got it all fixed now, thanks for the replies. :)
     
  33. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,681
    Hrm, if everyone votes on every feature it becomes hard to work out what to do :)
     
  34. blaze

    blaze

    Joined:
    Dec 21, 2011
    Posts:
    211
    Make a Poll for this Thread.
     
  35. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,681
    I've just added a whole page on the website for voting on features (see sig), but at the moment seems everyone wants everything :)

    Still a better way to manage them, as you can see whats being worked on and I will include videos in the details as things progress (click name to see details).
     
  36. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,681
    Slowly sorting out ladders, I might need some new animations for climbing top of ladder so might be a few weeks before its clean enough for release:


    [video=youtube_share;eb-CiKBbtww]http://youtu.be/eb-CiKBbtww
     
  37. parnell

    parnell

    Joined:
    Jan 14, 2009
    Posts:
    206
    Looks great.
    Let me know if you need anything;)
    Thanks!
    B
     
  38. p6r

    p6r

    Joined:
    Nov 6, 2010
    Posts:
    1,146
    After a lot of work/tests I could texture your nice character :

    $Robot2DPLC.png $Robot2DPLC2.png

    6R
     
  39. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,681
    Nice :)

    On another note, I'm starting to see some favourites emerge in the feature voting. Apart from things I've already started it looks like swimming is a popular choice.
     
  40. Jaans

    Jaans

    Joined:
    Apr 7, 2013
    Posts:
    28
    Looks like the Mecanim sample is not getting enough votes to be in the top three. Hopefully it is still coming, I could use some help with bringing my own 3d model and animations to the scene so that they properly use the controller. One feature that is not on the list might be a video tutorial explaining how to do this (or at least a bit more newbie friendly explanation in the manual :) )? Thanks again!
     
  41. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,681
    Howdy, Mecanim is in progress already so it will be done. Note I do have a simple Mecanim sample which you are welcome to, just send me your invoice number via email.

    - John A
     
  42. Talantyyr

    Talantyyr

    Joined:
    Nov 8, 2012
    Posts:
    10
    Hi,

    I'd like to suggest a few walljump features :)

    1) Make walljump possible only on walljump layers. Now it's working everywhere, which is kinda bothersome. If one makes a higher platform, which should be only reachable via ledge hanging / climbing. (Player is always wallsliding / jumping)
    2) Easy walljump. It allows you to jump up a single wall, as you can jump everytime you touch the wall. Jump only in opposite direction is no choice, though, as it would render the above point impossible.
    3) Stick to the wall, as you suggested earlier, kinda like Rayman origins.
     
  43. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,681
    1. That's certainly a possibility. Alternatively a specific platform class could be attached to a wall to make it wall jumpable.

    2. This doesn't sound like a request :) What do you want instead? Easy wall jump but only once on the same wall? That could work. (PS climbing wall with wall jumps was intentional to enable behaviour like popular platform games such as super meat boy).

    3. This is already implemented, enable wall slide and set the wall slide gravity factor to zero. Or do you want some alternative control for this?
     
  44. Talantyyr

    Talantyyr

    Joined:
    Nov 8, 2012
    Posts:
    10
    Hi John,

    Thanks for your reply!

    1.) Would be great if you could implement this! A walljump layer or something? i guess i can't do that my self :- /
    2.) What i meant:
    Easy walljump now allows the player to jump up one one wall... that's a nice feature, of course, but for me walljumping is between two walls.
    A great easy walljump feature would be, if the player jumps onto a wall, and sticks there (which is possible with the solution you've given at 3.), if one presses the jump button, the player would jump to the other side (which is possible with "wall jump only in opposite direction") and sticks there. So one could jump between two walls with only holding a direction key and pressing the jump button.

    Maybe it'd be also cool, if one doesn't need to hold a direction key, after sticking to the wall. The player could stick there for a defined time, e.g. 2 seconds or so

    The actual walljumping is working ok on my pc with the keyboard, where i can quickly switch the direction keys, but on my mobile with a virtual joystick, it's VERY hard to get up those walls. I've tried all possible solutions now (autostick with no wallslide, easy walljump, and so on) but it's rather frustrating to jump up a wall on a mobile device :(


    3.) Thx!
     
  45. Kersei

    Kersei

    Joined:
    Apr 29, 2013
    Posts:
    12
    Hi again John,

    Here i'm with another problem and asking for your help, my problem is with the ropes, when my character stick to the rope everything works just fine even when climbing the rope, my problem comes when i start swing in the rope, at first it swings fine but if i keep swinging my character start to move to the sides of the rope and eventually falls of the rope, could you tell why is this happening?, is there a bug or is just something that i misconfigured?. Thanks in advance for your answers.

    P.S. I have a request that i think is very simple for very useful, could you put a different autostick for the ladders and the ropes? what it mean with this is that the auto stick for the rope could be separated of the ladder one? that would be wonderful. i hope you consider this.
     
    Last edited: Jul 29, 2013
  46. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,681
    I have no trouble getting up between walls on mobile using the alternating direction approach. I'll check my settings in the project where I use this and see if its simply a settings thing ( as opposed to my amazing manual dexterity). Also have you tried easy wall jump off but a large wall jump time? This means you have to hold towards the wall and then press away and jump but with a large amount of leeway it shouldn't be too difficult.

    Anways I'll take a look at these (as well as your no direction key option), but it might be a few weeks before there is any progress... a LOT of updates in the pipeline at the moment.
     
  47. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,681
    Short answer I'm not sure. You shouldn't be able to "slide" off the ropes with default settings as in the demos, but if you deviate away from this there is some chance. Firstly make sure the rope colliders (the steps) are close enough together. Secondly there is certainly some limit to the amount of swing you have. If you have trouble feel free to send me the project.

    Cheers,
    John A
     
    Last edited: Jul 29, 2013
  48. TattooRose

    TattooRose

    Joined:
    Jul 3, 2013
    Posts:
    2
    Hi Johnny,

    I am writing a Mario Style 2d game and I would like to create a dying sequence once the actor is killed. I am very new to Unity and the 2D Platform Controller so please bear with me.

    I am using your package along with the 2D Toolkit in this project and I am working in the Hit Box script.

    What I have found is if I set the CharacterState using the ForceSetCharacterState method to STUNNED then the 2D Toolkit clip I am trying to play does appear. I would like to have the character move from the current Y position up for a certain period of time then have the game RESPAWN.

    Here is the code I am currently using:

    bool animationDone = false;
    CharacterProperties.Lives -= 1;
    var animator = GameObject.FindGameObjectWithTag("PlayerSprite");
    if (animator != null)
    {
    var animate = (tk2dSpriteAnimator)animator.GetComponent(typeof(tk2dSpriteAnimator));
    if (animate != null)
    {
    character.ForceSetCharacterState(CharacterState.STUNNED);
    animate.Play("smbDying");
    float y = character.Velocity.y;
    while (y < 11.0f)
    {
    character.transform.position = new Vector3(character.Velocity.x, y, 0.0f);
    y += 0.5f;
    Debug.Log("y = " + y);
    }
    animationDone = true;
    }

    }
    if (animationDone)
    {
    character.SendMessage("Die", SendMessageOptions.DontRequireReceiver);
    }


    What happens when this executes is the player does not float up from the current x position but instead is shown when the y level is greater than 11.0f. Also the characters moves over to the right on the x axis and that has me totally confused.

    Any help with this would be very appreciated.

    On another note, I would definitely vote for a dying state being added to the package.

    Thanks for all your work on this. Fantastic package!!!

    Victor
     
  49. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    4,681
    Hi Victor,

    firstly death state is on the list in my head, and I'll add it to the Feature Request page shortly. That said the list is pretty long so not quite sure when it will make it to release.

    For a death state I would suggest not using the controller. By that I mean there is flag on the controller called controllerActive which you can set to false. Something like this should do the trick (note code just typed in to the browser so I am sure there are mistakes):

    Code (csharp):
    1.  
    2. public class DeathListener : MonoBehaviour {
    3.   public RacyastCharacterController controller;
    4.   public AnimatorClass animator; //AnimatorClass is a reference to your animator class which might be (for example) based on AlienAnimator
    5.  
    6.   public float moveTime = 1.0f; // TIme the character rises up
    7.   public float speed = 5.0f; // Speed of rise
    8.   // If memory serves correctly this message is sent by SimpleHealth as one of the options for death, alternatively
    9.   // adjust your Health script to call this function.
    10.   public void Die() {
    11.      controller.active = false;
    12.      animator.Die(); // This will aniamte your sprite with your death animation, I've included it on the animator class instead of directly so all animations ar ein one place
    13.      StartCoroutine(DoDeath());
    14.   }
    15.   private IEnumerator DoDeath(){
    16.     float moveTimer = 0.0f;
    17.     while (moveTimer < moveTime) {
    18.       moveTimer += Time.deltaTime;
    19.       character.transform.Translate(0,speed*Time.deltaTime, 0);
    20.       yield return true;
    21.     }
    22.     // Restart level or call respawn here
    23.     Application.LoadLevel(Application.loadedLevel);
    24.   }
    25.  
    26. }
    27.  
    Note that I've down the actual death action in the death script not in simple health, I think it works better this way (so simple health triggers this script... at this point the character is dead, you are just showing an animation before resetting).
     
  50. Dan_Tsukasa

    Dan_Tsukasa

    Joined:
    Jan 26, 2013
    Posts:
    156
    Hey Johnny

    I'm currently trying to get pushing and pulling working in the 2D Toolkit example but I've run into an issue.

    So I've setup the Pull and Push states here:

    Code (csharp):
    1.  
    2.                 case CharacterState.STUNNED: Stunned(previousState); break;
    3.                 case CharacterState.PUSHING: Push(); break;
    4.                 case CharacterState.PULLING: Pull(); break;
    5.  
    And added this with all the other animations:

    Code (csharp):
    1.  
    2.     protected void Push() {
    3.         playerSprite.Play(  "Perfect_Push" + suffix);
    4.     }
    5.    
    6.     protected void Pull() {
    7.         playerSprite.Play(  "Perfect_Pull" + suffix);
    8.     }
    9.  
    10.  
    However the push works, somewhat, the object actually moves slowly, but the animation doesn't play, the animation flickers between the first frame of push and the first frame of idle/run (its difficult to tell as they look similar in frame 1).

    The pull doesn't work at all though, I've searched through the pullable box script and it simply refers to the states I've setup, and my state setup for push and pull is identical (minus using 2DTK) to yours with the Hero Character. It appears the issue is that it can't stick in the state for more than 1 frame, however I see nothing that decides that, so I'm a tad stumped.

    I don't know if you're perhaps adding it to the 2D Toolkit version anyway perhaps, but if you know the cause of this issue I'td be great.
    All my animations are several-20 frames long wheras your examples were only 1 or 2 frames long, but I shouldn't imagine this is the issue.
     
unityunity