Search Unity

[Released] 2D Platform Controller

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

  1. parnell

    parnell

    Joined:
    Jan 14, 2009
    Posts:
    206
    Will they working on moving platforms? That was probably the biggest issue I was having with pushing boxes was that they wouldnt acknowledge the platform or they'd bounce/jitter around on the platforms. You could parent them but then you couldn't push them off a moving platform at least when I tried.
    Very excited!
    Looks cool!
    B
     
  2. Kersei

    Kersei

    Joined:
    Apr 29, 2013
    Posts:
    12
    hi again, and thanks for the last answer you gave me, i have a little noob question (again), is there a way to put a sprite on the rope prefab?, and how do i do that?, and another one, is there a way to increment the size of the rope?, i hope you can answer me.
    P.S: You are doing a great work, i'm loving this asset a little more everyday
     
  3. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Yes they are based on the character so they work on moving platforms.
     
  4. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    For the rope you can replace the mesh object with a sprite. Each sprite will be a link in the rope. A more advanced approach would be to generate a dynamic mesh along the control points of the rope and then deform a sprite along this mesh... thats a bit more complicated though.

    For flexible ropes to increase the size of the rope you need to do the following:

    1. Duplicate the last rope section.
    2. Move the new section in to the right place (i.e. move it down so its y value is one less than the previous value e.g. -8 ).
    3. Set the hinge joint of the newly created section to be the previous section.
    4. Delete the last step from the old section (i.e. delete step8 from rope8 )


    Here's a screenshot which may help:

    $Screen Shot 2013-07-14 at 2.13.11 PM.png


    (yes i Know its a pain to work with, a rope tool was on the agenda but no one has asked for it)
     
    Last edited: Jul 14, 2013
  5. Dan_Tsukasa

    Dan_Tsukasa

    Joined:
    Jan 26, 2013
    Posts:
    155
    I wonder if this sort of rope physics would be possible using soft body physics, though that'd be a lot more overhead than what you currently have.

    I was also wondering how best to setup a new rope, as a sprite, I was at first going to wait until the 2DTK implimentation is complete, but I think I'll rush ahead anyway.

    Some minor additions to the controller such as the following may be interesting, though some may already be in the works.
    - Ability to push and pull at an entirely different speed to running or walking
    - Improved detection of slopes, so going upward could be added a new steep hill climb animation

    The consistent updates and your replies and help on this topic are awesome.
     
  6. Bast-I

    Bast-I

    Joined:
    May 28, 2013
    Posts:
    18
    I second these two suggestions. Perhaps you could take the handling of slopes even further: It would be great if one could decide whether the character rotates at all (or perhaps given a certain steepness) when climbing slopes.

    Is it to late to ask for that?

    Thanks for all this incredible bonus stuff from the last update! I am really looking to the Mecanim-support!
     
  7. Dan_Tsukasa

    Dan_Tsukasa

    Joined:
    Jan 26, 2013
    Posts:
    155
    I've not actually looked at Mechanim before (all my games have been 2D so far),
    The slope rotation already exists, if you check the Basic Hero sample and Basic samples (with the cube) Scenes, you can see it in action there.
     
  8. JohnnyA

    JohnnyA

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

    although I'll slowly add examples over time my focus will be moving back to core features (like Mecanim).

    Most of the things you are asking for can be achieved with small scripts that make use of existing features. I can't remember who is a coder and who is not but in the meantime some tips:


    You can allow slopes but turn off visual rotation by adding a script to your model (child of the controller) which sets rotation back to identity each frame.

    Push and pull speed could be set in the new example with a few lines (might add that add in before submission).

    You can alter speed based on the characters angle by adding a script which does something like this (psuedocode):

    if (angle < 90) velocity.x += hillSpeed * (90 - angle) * input.x
    else if (angle >270) velocity.x += hillSpeed * (360 - angle) * input.x * -1


    PS Bast I if you want the existing mecanim sample send me an email including your invoice #
     
  9. AMO_Noot

    AMO_Noot

    Joined:
    Aug 14, 2012
    Posts:
    433
    I don't suppose you have an existing 2DToolkit 2.0 sample as well, would you? Would love to see it, if you do.
    Edit: Tossed you an email, just in case.
     
    Last edited: Jul 15, 2013
  10. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Pretty sure the only sample I have is version 2.0:

    Here's a simple one I just started for my own game Solar Boy:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. /**
    5.  * Default animator for Solar Boy
    6.  */
    7. public class SolarBoyAnimator: MonoBehaviour {
    8.        
    9.     public RaycastCharacterController controller;
    10.     public tk2dSpriteAnimator playerSprite;
    11.    
    12.     private int currentDirection;
    13.  
    14.     void Start() {
    15.         // Register listeners
    16.         controller.CharacterAnimationEvent += new RaycastCharacterController.CharacterControllerEventDelegate (CharacterAnimationEvent);
    17.     }
    18.        
    19.     void Update ()
    20.     {
    21.         if (controller.characterInput.x != 0)
    22.             CheckDirection ();
    23.        
    24.     }
    25.        
    26.        
    27.     /// <summary>
    28.     /// Respond to an animation event.
    29.     /// </summary>
    30.     public void CharacterAnimationEvent (CharacterState state, CharacterState previousState) {
    31.        
    32.         switch (state) {   
    33.             case CharacterState.IDLE: Idle(); break;    
    34.             case CharacterState.SLIDING: Slide(previousState); break;    
    35.             case CharacterState.WALKING: Walk(); break;
    36.             case CharacterState.RUNNING: Walk(); break;  
    37.             case CharacterState.JUMPING: Jump(); break;
    38.             case CharacterState.AIRBORNE: Jump(); break;
    39.             case CharacterState.FALLING: Fall(); break;
    40.             case CharacterState.DOUBLE_JUMPING: Jump(); break;  
    41.             case CharacterState.WALL_JUMPING: Jump(); break;    
    42.         }
    43.        
    44.     }
    45.    
    46.     protected void Idle () {
    47.         playerSprite.Play("Idle");
    48.         CheckDirection();
    49.     }
    50.    
    51.     protected void Slide (CharacterState previousState) {
    52.         if (previousState == CharacterState.AIRBORNE || previousState == CharacterState.FALLING) {
    53.             playerSprite.Play("Idle");
    54.         }
    55.        
    56.     }
    57.    
    58.     protected void Walk () {
    59.         playerSprite.Play("Walk");
    60.         CheckDirection();
    61.     }
    62.    
    63.    
    64.     protected void Run () {
    65.         playerSprite.Play("Run");
    66.         CheckDirection();
    67.     }
    68.    
    69.     protected void Jump() {
    70.         playerSprite.Play("Jump");
    71.         CheckDirection();
    72.     }
    73.    
    74.     protected void Fall() {
    75.         playerSprite.Play("Fall");
    76.         CheckDirection();
    77.     }
    78.  
    79.     protected void CheckDirection ()
    80.     {
    81.         if (controller.CurrentDirection != currentDirection) {
    82.             currentDirection = controller.CurrentDirection;
    83.  
    84.             if (currentDirection > 0) {
    85.                 playerSprite.transform.localScale = new Vector3 (1, 1, 1);
    86.                        
    87.             } else if (currentDirection < 0) {
    88.                 playerSprite.transform.localScale = new Vector3 (-1, 1, 1);
    89.                        
    90.             }  
    91.         }
    92.     }
    93.  
    94. }
    95.  
    And here's the one from the 2DTK rope sample (which has a lot of extra code just to enable the rope swing to behave a bit differently):

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class TK2DPlatformAnimator : MonoBehaviour {
    6.        
    7.         public RaycastCharacterController controller;
    8.         public tk2dSpriteAnimator playerSprite;
    9.        
    10.         private int currentDirection;
    11.         private bool willPlayRopeHang;
    12.  
    13.         void Start(){
    14.            
    15.             // Register listeners
    16.            
    17.             controller.CharacterAnimationEvent += new RaycastCharacterController.CharacterControllerEventDelegate (CharacterAnimationEvent);
    18.            
    19.         }
    20.        
    21.     void Update ()
    22.     {
    23.         if (controller.characterInput.x != 0)
    24.             CheckDirection ();
    25.         if (willPlayRopeHang) {
    26.             if (playerSprite.CurrentFrame > 6) {
    27.                 playerSprite.Play("RopeHang");
    28.             }
    29.         }
    30.     }
    31.        
    32.        
    33.         /// <summary>
    34.         /// Respond to an animation event.
    35.         /// </summary>
    36.         /// <param name='state'>
    37.         /// State.
    38.         /// </param>
    39.         /// <param name='previousState'>
    40.         /// Previous state.
    41.         /// </param>
    42.         public void CharacterAnimationEvent (CharacterState state, CharacterState previousState) {
    43.            
    44.             switch (state) {
    45.             case CharacterState.IDLE: Idle(); break;    
    46.             case CharacterState.WALKING: Walk(); break;
    47.             case CharacterState.RUNNING: Walk(); break;  
    48.             case CharacterState.JUMPING: Jump(); break;
    49.             case CharacterState.AIRBORNE: Jump(); break;
    50.             case CharacterState.FALLING: Fall(); break;
    51.             case CharacterState.DOUBLE_JUMPING: Jump(); break;  
    52.             case CharacterState.WALL_JUMPING: Jump(); break;    
    53.             case CharacterState.LEDGE_HANGING: LedgeHang(); break;                 
    54.             case CharacterState.LEDGE_CLIMBING: LedgeClimb(); break;  
    55.             case CharacterState.ROPE_CLIMBING: RopeClimb(); break;
    56.             case CharacterState.ROPE_HANGING: RopeHang(); break;
    57.             case CharacterState.ROPE_SWING: RopeSwing(); break;
    58.             //case CharacterState.HOLDING: Hold(); break;
    59.             //case CharacterState.CLIMBING: Climb(); break;  
    60.             }
    61.         }
    62.        
    63.         protected void Idle () {
    64.             playerSprite.Play("Idle");
    65.             willPlayRopeHang = false;
    66.             CheckDirection();
    67.         }
    68.        
    69.         protected void Walk () {
    70.             playerSprite.Play("Walk");
    71.             willPlayRopeHang = false;
    72.             CheckDirection();
    73.         }
    74.                
    75.         protected void Run () {
    76.             playerSprite.Play("Run");
    77.             willPlayRopeHang = false;
    78.             CheckDirection();
    79.         }
    80.            
    81.         protected void Jump() {
    82.             playerSprite.Play("Jump");
    83.             willPlayRopeHang = false;
    84.             CheckDirection();
    85.  
    86.         }
    87.  
    88.         protected void Fall() {
    89.             playerSprite.Play("Fall");
    90.             willPlayRopeHang = false;
    91.             CheckDirection();willPlayRopeHang = false;
    92.            
    93.         }
    94.  
    95.         protected void Hold() {
    96.             willPlayRopeHang = false;
    97.             playerSprite.Play("Hold");
    98.         }
    99.  
    100.         protected void Climb() {
    101.             willPlayRopeHang = false;
    102.             playerSprite.Play("Climb");
    103.         }
    104.  
    105.         protected void LedgeHang() {
    106.         willPlayRopeHang = false;
    107.             playerSprite.Play("LedgeHang");
    108.             CheckDirection();
    109.        
    110.            
    111.         }
    112.        
    113.  
    114.         protected void LedgeClimb() {
    115.         willPlayRopeHang = false;
    116.             playerSprite.Play("LedgeClimb");
    117.            
    118.         }
    119.    
    120.  
    121.         protected void RopeHang ()
    122.         {
    123.             if (!playerSprite.IsPlaying ("RopeSwing")) {
    124.                 playerSprite.Play ("RopeHang");
    125.                 willPlayRopeHang = false;
    126.             } else {
    127.                 willPlayRopeHang = true;
    128.             }
    129.         }
    130.    
    131.         protected void RopeClimb() {
    132.             playerSprite.Play("RopeClimb");
    133.         }
    134.  
    135.         protected void RopeSwing() {
    136.             playerSprite.Play("RopeSwing");
    137.        
    138.         }
    139.  
    140.         protected void CheckDirection ()
    141.         {
    142.             if (controller.CurrentDirection != currentDirection) {
    143.                 currentDirection = controller.CurrentDirection;
    144.    
    145.                 if (currentDirection > 0) {
    146.                     playerSprite.transform.localScale = new Vector3 (1, 1, 1);
    147.                            
    148.                 } else if (currentDirection < 0) {
    149.                     playerSprite.transform.localScale = new Vector3 (-1, 1, 1);
    150.                            
    151.                 }  
    152.             }
    153.         }
    154.  
    155. }
    156.  
     
    Last edited: Jul 15, 2013
  11. AMO_Noot

    AMO_Noot

    Joined:
    Aug 14, 2012
    Posts:
    433
    Worked like a charm. My scripting abilities are pretty weak, so this helps a lot. Thanks John.
     
  12. Kersei

    Kersei

    Joined:
    Apr 29, 2013
    Posts:
    12
    Thanks a lot for the quick answer, and i apologize for not reading the instructions earlier, so i think that if i want to change the sprites of the ladders the mecanism would be very similar, or there is something different to do?, thanks to you my rope is working just fine.

    keep the great work
     
    Last edited: Jul 16, 2013
  13. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    For ladders you can just use one sprite (for example in 2D ToolKit you might use a single tiled sprite) if you want. A ladder doesn't move around so its visual component is pretty simple.

    To extend a ladder just drag in more ladder prefabs. You can fine tune the size by deleting the steps at the bottom of the ladder.
     
  14. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Just a list of planned updates with rough date for submission:

    20th July - Push pull example, tutorial video

    30th July - 2D Toolkit Sample

    10th August - Mecanim Sample

    All three of these things are in a state where they are usable, and I'm happy to send the WIP to anyone who is interested (please email the support address with your invoice number).
     
  15. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Oh just found some really nice public domain platform art... the 2D examples are now going to get a whole lot nicer :)
     
  16. fryiee

    fryiee

    Joined:
    Jan 28, 2013
    Posts:
    18
    Great to see another aussie here. I'm just about to pull the trigger on this, looks great and you seem to be really committed to a great product. I've just got a couple of questions if you don't mind:

    I see sloped terrain is useable, does that support fairly large curves? For reference, I'm working on a project that incorporates things that are best described as 'tendrils' - curly, with an emphasis on movement puzzles, for example:

    $example1.png

    Now I don't expect this to work out of the box with the movement puzzles (I fully intend to script that movement so it isnt a true physics calc), but I wanted to know if the slope implementation is solid in this to begin with that the character will track curves correctly(providing the colliders are set up correctly). Further to that, if the movement implementation is set up in a way that is easy enough for me to hook in to simulate sliding, speeding up on slopes and things like that. Based off the slope example in the demo video, it would be something like this:

    $example2.png


    Hopefully I explained that clearly enough. Thanks for a great product!
     
  17. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    To be honest I'm not sure you will get much from the package if that is your requirement. For a start the jump is always up (y=1) not normal to the slope. This is something I planned to make an option but no one has really asked for it.

    I'll try to take a look at this capability over the weekend.

    Regards,

    John A
     
  18. FelipeKras

    FelipeKras

    Joined:
    Apr 28, 2013
    Posts:
    5
    Hey guys.

    First of all, congratulations for the plug-in, it's so cool!

    So... I'm having an issue with the ladder.

    Now I have a question... How can I fix this little problem with top/bottom of the ladder that my character doesn't change the state to idle/walking?

    When I'm forcing to the top, for example, it's still on climbing state.
     
    Last edited: Jul 19, 2013
  19. JohnnyA

    JohnnyA

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

    Just to be clear I think this is what you are describing:

    1. Ladder has correct TopStep platform script.
    2. Climb to top of ladder.
    3. When you get to the top you stay in climb state instead of moving to an idle state.

    Is that correct, if so that sounds like a bug to me, I must admit I haven't done much on ladders for a while because no one asks about them.

    If you can confirm that behaviour I will check it out.

    - John A
     
  20. FelipeKras

    FelipeKras

    Joined:
    Apr 28, 2013
    Posts:
    5
    Yes, exactly!

    I've taken the ladder as prefab of the scene "BasicSample" and so I did some tests with it. Then I've encountered this issue.

    I appreciate your attention.
     
  21. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Try replacing your TopStepPlatform.cs code with this:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. /// <summary>
    6. /// Top step platform, this script should be attached to the top step of a ladder.
    7. /// </summary>
    8. public class TopStepPlatform : Platform {
    9.  
    10.     public float idleAnimationOffset;
    11.  
    12.     override public Transform ParentOnStand(RaycastCharacterController character) {
    13.         if ((character.transform.position.y - myTransform.position.y) > idleAnimationOffset) character.ForceSetCharacterState(CharacterState.IDLE);
    14.         return myTransform;
    15.     }
    16.    
    17. }
    18.  
    You can then adjust the idleAnimationOffset to determine at what height the character is forced to play the idle animation instead of the climb.

    This is a quick fix, but hopefully will address your immediate issue. I will be taking a good look at ladders eventually (and getting the animations set up on the Hero character).
     
  22. fryiee

    fryiee

    Joined:
    Jan 28, 2013
    Posts:
    18
    No problems John.

    I dont actually need jump along the normal, I just need to know how the package calculates movement - if it's rays directed at the normal with a velocity, I should be able to code a script that derives the slope angle and current velocity to see if the character should continue to 'stick', and then work out some form of movement continuation based on previous velocity once it leaves the ground.

    I feel like I'm explaining this really poorly, but if you do get a chance to think about it over the weekend that'd be great.

    EDIT: Essentially, 'sonic' style.
     
    Last edited: Jul 19, 2013
  23. FelipeKras

    FelipeKras

    Joined:
    Apr 28, 2013
    Posts:
    5
    Ok, that works. But now the character doesn't cycles through the other states while in the top of the ladder.

    Can you please do a support like that for the bottom of the ladder too? Just like the script "TopStepPlatform"? Or there is another way to handle that?

    Thanks.
     
  24. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Think I'm going to have to do a "proper" update, check all behaviour, running all tests, etc. Will definitely check it out this weekend.
     
  25. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Something like the Mario Sample rebuilt in 2D toolkit ... this will be in the next version:

     
  26. p6r

    p6r

    Joined:
    Nov 6, 2010
    Posts:
    1,158
    This will be in the next version ???????????????????????????????
    GREAT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    6R
     
  27. FelipeKras

    FelipeKras

    Joined:
    Apr 28, 2013
    Posts:
    5
    Nice, I'm looking forward to it.

    Btw, the new sample looks pretty nice!
     
  28. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
  29. parnell

    parnell

    Joined:
    Jan 14, 2009
    Posts:
    206
  30. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Update with 2D ToolKit Sample submitted. Price increased to $40 which should be the final price for a long time now, hope thats not considered too expensive. I also cleaned up the screenshots so hopefully Unity will do some sales and you can get it cheaper :)


    $2DPC-Screenshot1-Settings.png

    $2DPC-Screenshot2-3D.png

    $2DPC-Screenshot3-2DTK.png

    $2DPC-Screenshot4-Animation.png
     
  31. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    One other note, the 2D Toolkit controller in the sample is pretty simple, the more advanced controller (ledge climb etc) with the character from youtube will also be included in a future release.
     
  32. p6r

    p6r

    Joined:
    Nov 6, 2010
    Posts:
    1,158
    @ JohnnyA : You are the best !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    6R
     
  33. fryiee

    fryiee

    Joined:
    Jan 28, 2013
    Posts:
    18
    Ahh rats. Should've picked it up yesterday. But if I can make it work for my purposes, I'm more than happy to throw down that much cash :)
     
  34. PixelEnvision

    PixelEnvision

    Joined:
    Feb 7, 2012
    Posts:
    513
    Just purchased, great work...

    FYI, you can still grab it at $35. If you are interested, hurry up before the update goes live...
     
  35. AMO_Noot

    AMO_Noot

    Joined:
    Aug 14, 2012
    Posts:
    433
    Looking great, John. I wouldn't worry about the price point, $40 is still a damn good deal when the alternative is rolling your own from scratch or dealing with the unity capsule collider.
     
    Last edited: Jul 20, 2013
  36. Kersei

    Kersei

    Joined:
    Apr 29, 2013
    Posts:
    12
    Hey, good work with the updates, i have a little question about the Platform class, i need to know when my character is standing on it, but i try using this code to do that comprobation:
    Code (csharp):
    1.  
    2. if(  collider.direction == RC_Direction.DOWN){
    3.       //Do something
    4. }
    5.  
    but it only works when i jump on the platform, and i want to do it when i just step above it, i don't know if i made myself clear, in a simple question, how do i know when my character is on the platform? i hope you can help me.

    P.S. Great job with the demo
     
  37. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    What you have done should trigger when any foot collider hits the platform. Pretty confident that works as its how the sample for passthrough platforms, slippery platforms, etc, work.

    Assuming I'm trying to solve the right issue, maybe it will help to get all the code. You could also try some simple thing like adding a log statement or breakpoint outside the if statement.

    Code (csharp):
    1.  
    2. Debug.Log("Got a collision and the direction is: " + collider.direction);
    3. if(  collider.direction == RC_Direction.DOWN) {
    4. }
    5.  
     
    Last edited: Jul 21, 2013
  38. Kersei

    Kersei

    Joined:
    Apr 29, 2013
    Posts:
    12
    Ok my mistake not to put all the code, look at this:
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class PlataformaCayente : Platform {
    6.    
    7.     public GameObject mySprite;
    8.     public float stillTime = 2.0f;
    9.    
    10.     override protected void DoStart(){
    11.         mySprite = this.gameObject;
    12.     }
    13.    
    14.     override public void DoAction(RaycastCollider collider, RaycastCharacterController character){
    15.         Debug.Log("Jojoojo "+ collider.direction);
    16.         if(  collider.direction == RC_Direction.DOWN || character.characterInput.y < 0.0f ){
    17.             Debug.Log ("Time remaining: "+stillTime);
    18.             stillTime -= Time.deltaTime;
    19.             if(stillTime <= 0.0f){
    20.                 mySprite.rigidbody.useGravity = true;
    21.                 mySprite.rigidbody.isKinematic = false;
    22.             }
    23.         } else {
    24.             Debug.Log("reseting timer");
    25.             stillTime = 2.0f;
    26.         }
    27.     }
    28.    
    29.     override protected void DoUpdate(){
    30.     }
    31.    
    32.     override public Transform ParentOnStand(RaycastCharacterController character) {
    33.         return myTransform;
    34.     }
    35.    
    36. }
    37.  
    This code is trying to use your solution, it still not work, what i'm trying to achieve here, is a platform that falls 2 seconds (or any time i want) after i step on it, and if i jump before the time passes, the timer should reset, but i can make it work, any ideas?

    Thanks in advance for your answers
     
  39. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Try this:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. /// <summary>
    6. /// Platform that falls after you touch it. The fall is delayed by the
    7. /// value of fallDelay.
    8. /// </summary>
    9. public class FallingPlatform : Platform {
    10.    
    11.     public float fallDelay = 1.0f;
    12.     private bool fallStarted;
    13.  
    14.     override public void DoAction(RaycastCollider collider, RaycastCharacterController character) {
    15.         if (collider.direction == RC_Direction.DOWN  !fallStarted) {
    16.             fallStarted = true;
    17.             StartCoroutine(Fall());
    18.         }
    19.     }
    20.  
    21.     private IEnumerator Fall() {
    22.         yield return new WaitForSeconds(fallDelay);
    23.         rigidbody.isKinematic = false;
    24.         rigidbody.useGravity = true;
    25.     }
    26. }
    27.  
    Or for a timer version if thats what you want (decaying platform):

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. /// <summary>
    6. /// Platform that will fall if you stand on it for more than the decay time.
    7. /// The timer resets each time to you leave the platform so if you keep jumping
    8. /// you can stay on the platform.
    9. /// </summary>
    10. public class DecayingPlatform : Platform {
    11.    
    12.     public float decayTime = 1.0f;
    13.     private float standTime = 0.05f;
    14.     private bool fallStarted;
    15.     private bool characterIsOnMe;
    16.     private float decayTimer;
    17.     private float standTimer;
    18.  
    19.     void Awake () {
    20.         decayTimer = decayTime;
    21.     }
    22.  
    23.     void Update() {
    24.         if (!fallStarted  characterIsOnMe) {
    25.             standTimer -= Time.deltaTime;
    26.             decayTimer -= Time.deltaTime;
    27.             if (standTimer <= 0.0f) characterIsOnMe = false;
    28.             if (decayTimer <= 0.0f) Fall ();
    29.         } else if (!fallStarted) {
    30.             // You could remove this if you wanted the decay to be cumulative.
    31.             decayTimer = decayTime;
    32.         }
    33.     }
    34.  
    35.     override public void DoAction(RaycastCollider collider, RaycastCharacterController character) {
    36.         if (collider.direction == RC_Direction.DOWN  !fallStarted) {
    37.             characterIsOnMe = true;
    38.             standTimer = standTime;
    39.         }
    40.     }
    41.    
    42.     private void Fall() {
    43.         fallStarted = true;
    44.         rigidbody.isKinematic = false;
    45.         rigidbody.useGravity = true;
    46.     }
    47. }
    48.  
    The main key with the decaying platform is you need to have the "standTimer". When a character is standing on a platform they aren't always registering the raycast hit, so without the stand timer you would reset the decay too frequently.
     
    Last edited: Jul 21, 2013
  40. Kersei

    Kersei

    Joined:
    Apr 29, 2013
    Posts:
    12
    I see now, thank a lot for your help, the decaying platform is just what i needed, it acomplish the behaviour i wanted from the, if i just asked this earlier, it would have saved me a lot of time xD, but again thank so much man, you're the best
     
  41. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Hah no worries, I'll add these samples to the kit.
     
  42. p6r

    p6r

    Joined:
    Nov 6, 2010
    Posts:
    1,158
    2 questions :

    * Does it mean we absolutely have to use 2D Toolkit to use your great plugin for 2D games ?
    * Does it mean we can now use the 3D character without restrictions in our games ?

    6R
     
  43. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Everything except for free assets from the asset store has to be under the asset store license, in other words you could always use the 3D character without restrictions.

    You don't have to use 2D Toolkit, I've just created a demo with 2D toolkit because its the most popular toolkit. I will rebuild the existing sample level in Orthello next (mainly because its free), and then look at moving it to other assets.

    Note that everything in the 2D sample with work with other sprite solutions except for the bit that draws the sprite :)
     
  44. p6r

    p6r

    Joined:
    Nov 6, 2010
    Posts:
    1,158
    Thanks for your reply...

    For fun I have tried a simple Stones texture I was working on and here is the result. It looks like "The Thing" ! ;-)
    (And with this texture it seems to have eyes !?!)

    $Avatar2DPLC.png

    6R
     
  45. Fabian Schempp

    Fabian Schempp

    Joined:
    Jun 1, 2013
    Posts:
    17
    Hi Johnny, I would like to have an
    animated/moving ladder.
    But the character does Not move with the ladder
    Which he is climbing. Is there simple way to do this?
     
  46. Bast-I

    Bast-I

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

    I experimented with the falling platform code -- neat! There is a problem, though, if you make the platform fall slowly (and/or use high drag values in the platform's rigidbody physics settings). I am not sure whether I got it right but the problem seems to be this: When the platform is falling slower than your character the latter will bounce off the platform continously. What I would rather like to see is that the character stays on the platform (just as it is when being parented to a moving platform), at least up to a certain speed, and enters falling mode (and thus loosing the ability to walk on the falling platform) as soon as the platform's speed becomes greater than the falling speed of the character. Fiddling with the jump.fall.velocity didn't help as far as I can see.

    So how to circumvent this? Attaching an aptly configured (deactivated) up-and-down-platform-script to the falling platform that get's activated/called from the falling platform script or something along these lines? Or is there a way to leave the falling to unity's built-in physics and configure only the controller's behavior?

    I have another question which is pretty basic and concerns licensing, so I hope it is not too annoying to ask it here: I am about to take off for holiday and this means I will do my computer stuff on a different computer. Does this mean that I would have to buy another platform controller license for this one in order to work with it? (I am using the free Unity version.)

    Thanks to you all for this inspiring forum and to you, JohnnyA, for this great asset!

    Bast I
     
    Last edited: Jul 22, 2013
  47. BranDino

    BranDino

    Joined:
    Apr 12, 2013
    Posts:
    16
    Problem with flex Rope:
    Hey Johnny thanks for the recent updates I am pretty excited to try those out. So I read through this thread for references to the " Flex Rope " to find out why my character isn't climbing. He is able to jump and stick to to the rope, and make it swing back and forth, but I only get 1 maybe 2 climb translations (sends the "Has Climbed" message 1 or 2 times to the rope inspector) and then it refuses to climb again until I jump of and back on, no matter what size the rope is? My character is smaller than your hero and .1 or .2 x scale rope looks about right (I had slightly better luck with .1 y scale rope but not significant and tried at xyz 1 and same issue).

    troubleshooting facts: I have the latest 2dPlatformer ver (downloaded today). I have default animations for all the climbing states, I have the Raycast inspector climb set to the same as your hero sample, I send animation events each frame and have direction checker script attached. I am using 2dtoolkit version 2 Final + Hotfix, I think there is a more recent version not sure if that is a factor or not with my climbing issue seems like a Raycast Controller translation issue... Hope this is a quick fix prob something simple I have overlooked has anyone had and solved this issue....?
    {Thanks}
    Update
    if (issue = solved)
    {
    many thanks!;
    }
    } haha
     
  48. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    HI Bast I,

    If you want to fall slowly you will need to parent the character to the platform. That mechanism is built into the base platform class:

    Code (csharp):
    1.  
    2.   override public Transform ParentOnStand (RaycastCharacterController character) {
    3.     return myTransform;
    4.   }
    5.  
    You could make him fall off the platform once it gets too fast, but note that once you aren't on the platform you wont be able to jump any more so that might feel a bit weird. Something like this should do that:

    Code (csharp):
    1.  
    2.     override public Transform ParentOnStand (RaycastCharacterController character) {
    3.         if (rigidbody.velocity.y > velocityForFall) {
    4.             return myTransform;
    5.         }
    6.         if (character.transform.parent != null) {
    7.             character.Velocity = new Vector2 (character.Velocity.x, rigidbody.velocity.y);
    8.             character.transform.parent = null;
    9.         }
    10.         return null;
    11.     }
    12.  
    As for license you don't need another copy to work on a different computer.

    - John A
     
    Last edited: Jul 22, 2013
  49. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    I think you might need to add more steps if your character has smaller feet colliders. At the moment I think there are 3 steps per rope spaced about 3.3 world units apart. You might need to make 4 or 5 steps with thinner colliders spaced closer together. Basically you need a raycast to be going from outside a step to inside a step at all times for the character to be able to climb.

    Its a little bit of a hassle to get right up but once you have one "rung" (rope section) set up, you can just duplicate this.

    If you have further troubles and can send me a sample that might be the easiest way forward.

    Cheers,

    John A
     
  50. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    If you add a platform behaviour like this:

    Code (csharp):
    1.  
    2. public class LadderPlatform : Platform {
    3.     override public Transform ParentOnStand (RaycastCharacterController character) {
    4.         return myTransform;
    5.     }
    6. }
    7.  
    to EVERY step except for the top step it should work. Only issue might be the top step platform but it might be okay.

    Note that ladders will be getting an overhaul in the next few weeks. This will include making it easier to create them but also sample animations, and easier settings. I'll ensure I include moving ladders in this update.