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
    Here's n input you can quickly use to set up a controller, its configured for PS3 controller as that is what I own, but you can plug in any other buttons you want:

    Code (csharp):
    1.  
    2. public class RawButtonInput : RaycastCharacterInput {
    3.  
    4. public KeyCode upButton = KeyCode.Joystick1Button4; // PS3 D-Pad Up
    5. public KeyCode downButton = KeyCode.Joystick1Button6; // PS3 D-Pad Down
    6. public KeyCode leftButton = KeyCode.Joystick1Button7; // PS3 D-Pad Left
    7. public KeyCode rightButton = KeyCode.Joystick1Button5; // PS3 D-Pad Right
    8. public KeyCode jumpButton = KeyCode.Joystick1Button14; // PS3 X
    9. public KeyCode runButton = KeyCode.Joystick1Button11; // PS3 R1
    10. public KeyCode swimButton = KeyCode.Joystick1Button14; // PS3 X
    11.  
    12. /// <summary>
    13. /// IF true always run.
    14. /// </summary>
    15. public bool alwaysRun;
    16.  
    17. /// <summary>
    18. /// If true dropping from a passthrough platform requires user to press down and then jump.
    19. /// </summary>
    20. public bool jumpAndDownForDrop;
    21.  
    22. private int movingDirection;
    23.  
    24. void Update ()
    25. {
    26.  
    27. {
    28. if (Input.GetKey(KeyCode.R)) {
    29. Application.LoadLevel(0);
    30. }
    31.  
    32. jumpButtonHeld = false;
    33. jumpButtonDown = false;
    34. dropFromPlatform = false;
    35. x = 0;
    36. y = 0;
    37.  
    38. if (Input.GetKey(rightButton) && !Input.GetKey(leftButton)) {
    39. x = 0.5f;
    40. movingDirection = 1;
    41. } else if (Input.GetKey(leftButton) && !Input.GetKey(rightButton)) {
    42. x = -0.5f;
    43. movingDirection = -1;
    44. } else if (Input.GetKey(rightButton) && Input.GetKey(leftButton)){
    45. x = movingDirection / 2.0f;
    46. }
    47.  
    48. // Shift to run
    49. if (alwaysRun || Input.GetKey(runButton)) {
    50. x *= 2;
    51. }
    52.  
    53. if (Input.GetKey(upButton) ) {
    54. y = 1;
    55. } else if (Input.GetKey(downButton) ) {
    56. y = -1;
    57. if (!jumpAndDownForDrop) dropFromPlatform = true;
    58. }
    59.  
    60. if (Input.GetKey(jumpButton) ) {
    61. jumpButtonHeld = true;
    62. if (Input.GetKeyDown(jumpButton)) {
    63. if (jumpAndDownForDrop && Input.GetKey(downButton)) {
    64. dropFromPlatform = true;
    65. } else {
    66. jumpButtonDown = true;
    67. }
    68. swimButtonDown = true;
    69. } else {
    70. jumpButtonDown = false;
    71. swimButtonDown = false;
    72. }
    73. } else {
    74. jumpButtonDown = false;
    75. swimButtonDown = false;
    76. }
    77. }
    78.  
    79. }
    80. }
    81.  
     
  2. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    While waiting for a bigger release to be finished I thought I'd push this little platform game out to the app store. Its a pretty fun little mechanic if I do say so myself.

    This game uses a slightly modified version of the controller including the out-of-the-box touch input. You can see that it performs great and the controls feel very tight. I hope to see your iOS releases too!

     
  3. KidSicarus

    KidSicarus

    Joined:
    Feb 3, 2014
    Posts:
    35
    Very cool.

    Can't wait for PRO though!

    Your Achilles feeling good?
     
  4. Xevoius

    Xevoius

    Joined:
    Sep 26, 2012
    Posts:
    25

    Are you still taking submissions? I would like to submit a video of my game. I am going on vacation next week so I don't want to miss the deadline.

    Thanks!
     
  5. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    For sure, haven't got a lot of submissions yet, so I haven't created the video.
     
  6. The_Daleatron

    The_Daleatron

    Joined:
    Nov 26, 2013
    Posts:
    43
    Stupid question from me as usual, just wondering about some thing im looking to purchase this dialog system
    Wouldn't cause any conflicts with this would it ? i remember having an issue with playmaker.
     
  7. vidjo

    vidjo

    Joined:
    Sep 8, 2013
    Posts:
    97
    Whats the expected release on Platformer Pro?
     
  8. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    No date set so far.

    - - - -

    @The_Daleatron - 2DPC was written before namespaces were usable on MonoBehaviours so you may have name clashes. I can't say specifically if there is or isn't with that system, although I wouldn't expect many class names to overlap with a Dialog system. I'm happy to help you resolve.refactor if required.
     
  9. rushzero

    rushzero

    Joined:
    Jul 1, 2014
    Posts:
    2
    Hi,

    i have problems with the 2D Platform Controller...
    I falling all the time through the floor.

    What i am doing wrong?


    1. I create a Cube as Floor
    2. I create a Cube as Player
    2a. Add to the Player the RayCastCharacterController
    2b Add Simple Character Input
    2c Add Direction Checker
    2d Add 2b and 2c to the RayCastCharacterController Script
    3. Set all object into the same z-coord
    4. Press "play"

    ==> Result is that the cube fall through the Floor.
     
  10. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    I always recommend that you start from a prefab and adapt to your needs. Its MUCH easier to adapt existing character than create a new one.

    A few things come to mind: In your list you haven't mentioned anything about creating colliders, by default the character wont have any ray cast colliders. You haven't mentioned creating colliders on the floor (Unity does that when you create a cube so probably okay). You haven't mentioned what layers the objects are on and if that layer matches the background layer for your character.

    But again, there's no situation where I recommend creating from scratch. Just grab Hero or Alien prefabs and switch in your own models/animations.

    - John A
     
  11. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Here's some quick notes on how to add creeping (moving forward while crouching), as you may remember I didn't include this as I had no animations for it, so the change itself is extremely simple:


    Code (csharp):
    1.  
    2. protected void MoveInXDirection (bool grounded)
    3. {
    4. // Create a copy of character input which we can modify;
    5. float characterInputX = characterInput.x;
    6.  
    7. // Ignore input if stunned
    8. if (stunTimer > 0.0f)
    9. characterInputX = 0.0f;
    10.  
    11. // Ignore input if crouching COMMENT THESE TWO LINES OUT
    12. //if (isCrouching)
    13. // characterInputX = 0.0f;
    14.  

    If you use physics like movement it will be a bit slow, digital will be at same speed as walk speed. Obviously you could add additional conditions to change the speed. For example to creep at half walk speed in digital mode change lines 652:

    Code (csharp):
    1.  
    2. caseMovementStyle.DIGITAL:
    3. if (climbing.allowClimbing && startedClimbing) {
    4. velocity.x = (characterInput.x > 0 ? 1 : -1) * climbing.horizontalSpeed;
    5. } elseif (walking || isCrouching) {
    6. velocity.x = (characterInput.x > 0 ? 1 : -1) * movement.walkSpeed * (IsSwimming ? (1 - swimming.waterResistance.x) : 1) * (isCrouching ? 0.5f : 1.0f);
    7. } else {
    8. velocity.x = (characterInput.x > 0 ? 1 : -1) * movement.runSpeed * (IsSwimming ? (1 - swimming.waterResistance.x) : 1);
    9. }
    10. break;
    11.  


    For animations add something like this to the end of MoveInXDirection function (around line 870):

    Code (csharp):
    1.  
    2. // Animation
    3. if (grounded) {
    4.  
    5. // NEW CODE
    6. if (isCrouching && characterInput.x != 0.0f) {
    7. State = CharacterState.CREEPING;
    8. } else
    9. // END NEW CODE
    10. if ( (velocity.x > movement.walkSpeed && characterInput.x > 0.1f) ||
    11. (velocity.x < movement.walkSpeed * -1 && characterInput.x < -0.1f)) {
    12. State = CharacterState.RUNNING;
    13. } else if...
    14.  
    You will also need to add that state to the CharacterState class in SupportingClases.cs:
    Code (csharp):
    1.  
    2. CROUCHING = 180,
    3. CROUCH_SLIDING = 190,
    4. CREEPING = 191,
    5.  
     
  12. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Just submitted my first update for a while (v1.9.1) includes a few bug fixes and a much easier to use 2D animator.

    Here's a video:



    - - -​
    On the negative side my asset server decided to lose all my changes, so I don't have all the bug fixes and improvements I wanted to submit. If anyone happens to have a bug fix I have sent them please let me know so I can add it if I haven't already.
     
    Last edited: Jul 5, 2014
  13. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    Will this also work with the 2D Toolkit animation system?
    Is this also going to be the animator of 2D Platformer PRO?
     
  14. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    1. No, the existing 2DTK animator works in a similar same way (define 2DTK animations with the same name as the state).

    2. Just like 2DPC, Platfomer Pro has many animators. I now call them animation bridges: they are bridge between the animation events and variables of the controller and the animation system of your choice. I will include several bridges on release. You can also write your own, they tend to to be simple.
     
  15. KidSicarus

    KidSicarus

    Joined:
    Feb 3, 2014
    Posts:
    35
    Great work, Johnny.

    In your opinion, while working with various animation techniques, what is your preference in ease-of-use and power?

    I have been using Sprite Factory but am considering 2DTK. With both you can build in hitboxes and add calls for sound and particles per frame, but Platformer PRO also seems to have a lot of this functionality.

    Could you give us your thoughts on the route you would take, personally, knowing what you know, and knowing what Platformer PRO will have to offer? What would be your choice not just at the moment but also for the future and Platformer PRO?

    Thank you, sir. And keep it up!
     
  16. Xevoius

    Xevoius

    Joined:
    Sep 26, 2012
    Posts:
    25
    Issue Solved - tried out about 4 options, Fraps was the smoothest with my old video card.

    So I would like to put together a video for the game I am working on and how it uses 2D Platform Controller and I would like to get HD footage of the game play. Does anyone have a recommendation on what software I should purchase for gameplay screen capture?

    Win 8.

    Cheers.
     
    Last edited: Jul 7, 2014
  17. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Platformer PRO will focus on Unity 2D and 3D with Mecanim initially. 2DTK is something I own and have used a lot in the past, so I will likely support that from day one. Legacy 3D may be supported from day one as well. Other systems will not be supported straight away, but keep in mind that writing an animation bridge tends to fall somewhere between easy and trivial.

    As you say particles and hit boxes are addressed in Platformer PRO but it wont be at the per frame level offered by 2DTK. I will aim for the attack system to be automatically integrated with that feature.
     
  18. The_Daleatron

    The_Daleatron

    Joined:
    Nov 26, 2013
    Posts:
    43
    Use this its free, best one around at the moment as far i found anwyay.
    https://obsproject.com/
     
  19. KidSicarus

    KidSicarus

    Joined:
    Feb 3, 2014
    Posts:
    35
    That sounds great.

    Thanks!
     
  20. Collider_nyc

    Collider_nyc

    Joined:
    Jan 13, 2014
    Posts:
    14
    Just got the update a few minutes ago... much much easier to use with mechanim, thanks for that!
     
  21. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Some bugs in the 1.9.1 release. Here's a fix to add direction changing to animation bridge, am looking at the missed animation state issue now.

    Thats what I get for rushing out a build. Sorry :s
     

    Attached Files:

  22. Collider_nyc

    Collider_nyc

    Joined:
    Jan 13, 2014
    Posts:
    14
    Ah, thanks! I thought the direction change thing was just me as I'm using this with Spine. Was going to fix it today, you saved me some work :)
     
  23. theRiley

    theRiley

    Joined:
    Jun 7, 2014
    Posts:
    4
    Great package, and thanks for the 1.9.1 build to fix animation bridge, glad i checked here.

    Any advice from anyone using this package on how to do a character walking on the ceiling? I've tried setting the Gravity for the project to a positive amount, and switching the head/feed raycast settings, but when something gets funky with the acceleration, because the character will move on the ceiling, but wont' stop sliding back and fourth.

    I just need gravity to change for this one character when a button is pressed. Before rebuilding the project using this package would just alter the "rigidbody2D.gravityScale". But not without rigid body i'm trying to catch up.

    Any help from anyone is appreciated. Thanks!
     
  24. fabiobh

    fabiobh

    Joined:
    May 28, 2013
    Posts:
    92
    I see this asset in unity store and I like very much, but it have one problem, it's not possible to kill the enemy in the final part of the 2d demo. Do you plan to create something that make this possible?
     
  25. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    @theRiley Walking on the is not supported. The easiest way to do it is rotate/flip your level (with camera fixed to the level too). To change the controller to support alternate gravities would take quite a bit of customisation.

    @fabioh There are basic enemy samples in the kit which include an enemy you can kill by jumping on its head, however the enemies and damage systems are only illustrative, not a core mechanism.
     
  26. AndrewKennedy3D

    AndrewKennedy3D

    Joined:
    Aug 1, 2013
    Posts:
    4
    Hey Johnny, are you still working on the promo video?

    I don't have a fully developed commercial game, but I have used your controller in a few Ludum Dare games, and my recent one got very good attention and placed 19th overall. If you'd like, I can get you a video of it. Please let me know!

    http://www.ludumdare.com/compo/ludum-dare-29/?action=preview&uid=20990
     
  27. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Only got a few responses but I'm still hoping to collect some more footage, worse case I'm happy to promote your footage on my youtube channel.

    - John A

    PS Thats a really good entry for LD, well done!
     
  28. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    any tutorial for add animation like atk please please
     
  29. The_Daleatron

    The_Daleatron

    Joined:
    Nov 26, 2013
    Posts:
    43
    Still modelling most of my stuff at the moment, but when i finally get working on the game in unity it should look fairly nice hopefully anyway, probably be a few weeks till im at the stage. So no footage from me at the moment. Any idea when their will be a public release of those new systems your working on ? wouldn't mind trying to start setting some of what i have up with it at the moment.

    Also i dont suppose anyone could recommend a trap system from the asset store im having a hard time finding one.
     
  30. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    NO release date as yet. Am working on something so stay tuned.

    No idea about a trap system. Could you elaborate a little more on what it would do?
     
  31. The_Daleatron

    The_Daleatron

    Joined:
    Nov 26, 2013
    Posts:
    43
    Ok no worries, Im just looking for some sort thing where i can swap out my animated props on some kind of pre set traps with triggers or some such thing. I found one for $5 on the market there, twas the only one around.
     
  32. Xevoius

    Xevoius

    Joined:
    Sep 26, 2012
    Posts:
    25
    I wanted to post my first preview release footage of The Gordian Knot using your 2D Platform Controller package . Please take this as a submission to the gameplay footage video you are putting together Johnny.

    Oh, and I just launched a website for the game yesterday too.

    Thanks!

     
    Last edited: Aug 15, 2014
    The_Daleatron likes this.
  33. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Cool, I tweeted it too :)
     
  34. Xevoius

    Xevoius

    Joined:
    Sep 26, 2012
    Posts:
    25
    Thanks Johnny!
     
  35. Claymore

    Claymore

    Joined:
    Oct 17, 2012
    Posts:
    158
    Hi JohnyA! "Directon Checker" in Hero Sample. I want to create variable of Current Direction (i want to change players direction when something happens),i tried to edit this line : virtual public int CurrentDirection {get; private set;} TO
    public int CurrentDirection = 1; well it worked,but all got very buggy like ledge hanging and directions just messed up.
    I Need your help to create current direction variable and that i can controll it in game without glitching,please help me out!
     
  36. mousse

    mousse

    Joined:
    Oct 3, 2013
    Posts:
    27
    I really feel like throwing money at you JohnnyA and seeing if a Platformer PRO version pops out! I hope things are progressing and your doing ok/all is well!

    This and The Hobbit part 3 man. =)
     
  37. bizilux1

    bizilux1

    Joined:
    Jun 6, 2013
    Posts:
    151
    hello, i have one question

    how can i make controls feel more like in this game:

    http://armorgames.com/play/13990/portal-2d

    mainly i need to know how to almost disable air controls, when player jumps i want to give them very little movement controls when player is in air... right now player has A LOT of controls, which is fine for some games, but not for what im trying to do
     
  38. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    For some I'm no longer getting alerts on this thread (well the reason would be me changing my settings and getting the opposite of what I wanted).

    Firstly a little self promotion: DraCola Dash is available for early access NOW in Australia, NZ, China and France. Its an endless runner for iOS based on an old version of 2DPC. For people in those countries you can get it here:

    https://itunes.apple.com/au/app/dracola-dash/id845799891?mt=8

    For everyone else here's the teaser page: http://dracoladash.com/

    DracolaDashOnAppStore.png


    Replies to stuff above coming shortly.
     
    The_Daleatron likes this.
  39. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    here's a sample direction checker that flips character dir when you press f:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class DirectionCheckerSpecial : DirectionChecker {
    6.  
    7. public RaycastCharacterController character;
    8.  
    9. virtual public void FlipDirection() {
    10.   if (character.State == CharacterState.IDLE || character.State == CharacterState.SLIDING) {
    11.     character.Velocity = new Vector2(0.0f, character.Velocity.y);
    12.     CurrentDirection *= -1;
    13.     SwitchColliders(character);
    14.    }
    15. }
    16.  
    17. void Update() {
    18.   if (Input.GetKeyDown(KeyCode.F)) FlipDirection();
    19. }
    20.  
    21. }
    22.  
    I did need to make one change to Direction Checker as it a private variable that should be protected (around line 23 ensure the setter is protected not private:

    Code (csharp):
    1.  
    2. ///<summary>
    3. ///Thecurrentdirectionbeingfaced. 0 = NONE, 1 = RIGHT
    4. /// -1 = LEFT.
    5. ///</summary>
    6. virtual public int CurrentDirection {
    7.   get; protected set;
    8. }
    9.  
    To use in HeroSample delete current DirectionCheck, drop that character in and assign character to the public variable AND the direction checker to the RaycastCharacterController.
     
    Last edited: Aug 24, 2014
  40. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Probably easiest to write a custom input. Here's an input that lets you reduce the strength of the jump controls using a float value. Note for this to work you must use PHYSICS_LIKE movement style.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. /// <summary>
    6. /// A simple character input. Arrows to move, left SHIFT to run, SPACE to jump.
    7. /// </summary>
    8. public class SimpleCharacterInputWithJumpControl : RaycastCharacterInput
    9. {
    10.  
    11.     /// <summary>
    12.     /// IF true always run.
    13.     /// </summary>
    14.     public bool alwaysRun;
    15.  
    16.     /// <summary>
    17.     /// If true dropping from a passthrough platform requires user to press down and then jump.
    18.     /// </summary>
    19.     public bool jumpAndDownForDrop;
    20.  
    21.     /// <summary>
    22.     /// Adjust influence of left/right during jump (0 means no influence).
    23.     /// </summary>
    24.     public float jumpControl;
    25.  
    26.     /// <summary>
    27.     /// The character.
    28.     /// </summary>
    29.     public RaycastCharacterController character;
    30.  
    31.     private int movingDirection;
    32.  
    33.     void Update ()
    34.     {
    35.        
    36.         if (Input.GetKey(KeyCode.R)) {
    37.             Application.LoadLevel(0);
    38.         }
    39.        
    40.         jumpButtonHeld = false;
    41.         jumpButtonDown = false;
    42.         dropFromPlatform = false;
    43.         x = 0;
    44.         y = 0;
    45.        
    46.         if (Input.GetKey("right") && !Input.GetKey("left")) {
    47.             x = 0.5f;
    48.             movingDirection = 1;
    49.         } else if (Input.GetKey("left") && !Input.GetKey("right")) {
    50.             x = -0.5f;
    51.             movingDirection = -1;
    52.         } else if (Input.GetKey("right") && Input.GetKey("left")){
    53.             x = movingDirection / 2.0f;
    54.         }
    55.    
    56.         // Shift to run
    57.         if (alwaysRun || Input.GetKey(KeyCode.LeftShift)) {
    58.             x *= 2;
    59.         }
    60.        
    61.         if (Input.GetKey("up") ) {
    62.             y = 1;
    63.         } else if (Input.GetKey("down") ) {
    64.             y = -1;
    65.             if (!jumpAndDownForDrop) dropFromPlatform = true;
    66.         }
    67.        
    68.         if (Input.GetKey(KeyCode.Space) ) {
    69.             jumpButtonHeld = true;
    70.             if (Input.GetKeyDown(KeyCode.Space)) {
    71.                 if (jumpAndDownForDrop && Input.GetKey("down")) {
    72.                     dropFromPlatform = true;
    73.                 } else {
    74.                     jumpButtonDown = true;  
    75.                 }
    76.                 swimButtonDown = true;  
    77.             } else {
    78.                 jumpButtonDown = false;      
    79.                 swimButtonDown = false;
    80.             }
    81.         } else {
    82.             jumpButtonDown = false;
    83.             swimButtonDown = false;
    84.         }
    85.  
    86.         // The new code
    87.         if (character && (character.State == CharacterState.AIRBORNE || character.State == CharacterState.JUMPING || character.State == CharacterState.FALLING)) {
    88.             x*= jumpControl;
    89.         }
    90.     }
    91.    
    92. }
    93.  
    94.  
    Only those last few lines are new code.

    Drop it in your scene, make sure you remove your old input, and assign this to the characters input (and also assign the character to this).

    A value of 0 in the jumpControl will mean you can't change jump direction, for something like the game you pointed to with a tiny little bit of control try a value like 0.05.

    - John A
     
  41. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Interesting you mention that. I've been thinking about a small Kickstarter/IndieGoGo crowdfunding campaign for Platformer PRO. Basically enough so I can take some time of work, hire someone to write the doco/tutorials, and maybe an artist to do a nice demo as a stretch goal.

    Planning on doing some updates today regardless, but I wonder if there would be interest in such a campaign.
     
  42. Claymore

    Claymore

    Joined:
    Oct 17, 2012
    Posts:
    158
    Hi JohnyA. I dont understand that new version. First of all its showing me errors:

    The name `newVector2' does not exist in the current context
    Then i deleted that line and set up everything without it and error:

    The same field name is serialized multiple times in the class or it's parent class. This is not supported: Base(DirectionCheckerSpecial) <CurrentDirection>k__BackingField

    Naaaa just mess!

    Dont have any idea how to get rid of it. And is there a easier way to do this? Like just adding variable to current DirectionChecker script? It would be much easier i think,to edit it direction through another script.
    Thanks JohnyA! You are very helpful person!
     
    Last edited: Aug 23, 2014
  43. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    When I pasted it it got a bit messed up. I've edited it. You took out the line that does the actual flip.

    The second edit is a change to the original direction checker. Not to the special one.

    You can edit the original direction checker instead of writing a new one, if you want. The code that is doing the work is:

    Code (csharp):
    1.  
    2. if (character.State == CharacterState.IDLE || character.State == CharacterState.SLIDING) {
    3.    character.Velocity = new Vector2(0.0f, character.Velocity.y);
    4.     CurrentDirection *= -1;
    5.     SwitchColliders(character);
    6. }
    7.  
    You need to do most of that. The if condition makes sure you only flip when you are in a safe state to do so (for example you can't flip while running, or while in the middle of a ledge hang).

    The second line makes sure the character stops moving when they flip. You could probably remove this but it will mean you might flip whilst sliding and thus end up sliding backwards.

    The third line does the flip.

    And the forth line switches colliders. You only need this if you have an asymmetrical collider, however I'd recommend that you write code that works for all cases not just one special case.
     
  44. Claymore

    Claymore

    Joined:
    Oct 17, 2012
    Posts:
    158
    Okay,so i did everything you said,but problem now is that it only flips colliders not character,when i start the scene i also get this error:
    The same field name is serialized multiple times in the class or it's parent class. This is not supported: Base(DirectionCheckerSpecial) <CurrentDirection>k__BackingField

    i can flip only character colliders not character.
     
  45. vidjo

    vidjo

    Joined:
    Sep 8, 2013
    Posts:
    97
    Johnny, I will support your kickstarter for Platformer Pro.
     
  46. robinball

    robinball

    Joined:
    Jan 1, 2013
    Posts:
    48
    I'd be happy to throw some money your way to kickstart Platformer Pro too.
     
  47. outtoplay

    outtoplay

    Joined:
    Apr 29, 2009
    Posts:
    741
    Agreed... whatever you need, Johnny. I'm sure you'll get full support from those who have experienced your work and great customer support.
     
  48. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    Yep, would support/back the project! :)
     
  49. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    @Claymore

    Hi mate, can you raise this via support channel send a sample. The code I sent is working fine for me but its a bit hard to know exactly what your problem is without seeing it.

    - John A
     
  50. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Thanks everyone for your support. I'll keep you in the loop with what is happening re: Platformer PRO and funding.