Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[Released] 2D Platform Controller

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

  1. RandAlThor

    RandAlThor

    Joined:
    Dec 2, 2007
    Posts:
    1,291
    My best wishes for your family and a warm welcome for your newborn :)
     
  2. The_Daleatron

    The_Daleatron

    Joined:
    Nov 26, 2013
    Posts:
    43
  3. MarioRuiz

    MarioRuiz

    Joined:
    Nov 7, 2009
    Posts:
    161
    @Grohowiak I see a mecanim character/animator and a scene, the scene reads beta though.
     
  4. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    The Mecanim Animator is still listed as Beta as it doesn't quite have all the animations but it has all the main ones and work fine. What is shown in the channel is in the package. The animations are retargetable using Mecanim, but ledge climb comes out a little bit off due to the shape of the Hero Character. If you add some target matching this should be fine.

    Regards,

    John A
     
  5. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Thanks for all the well wishes guys.

    Stay tuned I'll have an accurate list of features and a timetable for the 2.0 update in the next few days.
     
  6. kauaiBlake

    kauaiBlake

    Joined:
    Feb 28, 2013
    Posts:
    36
    Hey Johnny, congrats on the new baby! Its a fun adventure, I personally love being a daddy, even though it can be hard at times, overall its such a blessing.
     
  7. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Here's a snapshot of the notes I put together about what I want to achieve in v2.0. Still don't have a final timeline but am very much hoping I can be done before i head back to work.

    - John A

    $Screen Shot 2013-12-15 at 11.40.20 am.png

    Open in a new window/tab to get a larger size.​
     
  8. AMO_Noot

    AMO_Noot

    Joined:
    Aug 14, 2012
    Posts:
    431
    Congrats, Johnny!

    2.0 notes are looking nice as well!
     
  9. Jioz

    Jioz

    Joined:
    Dec 16, 2013
    Posts:
    1
    Hi John. First of all, congratulations!
    this controller looks promising and i'm thinking about buying it. However i wanted to ask a few questions first.
    I played the two demos and it seems to me that the movement is intended to be somewhat realistic. What i want to achive is more kind of a donkey kong country like movement.
    Specifically this means:
    - When falling the player should quickly reach a set speed and not accelerate any further.
    - When juming/airborne and the player is letting go of the move keys, he should reach a horizontal speed of 0 in a set amount of time and not keep the momentum. In fact horizontal speed should always be 0 unless the player inputs to do otherwise, with the exception of moving platforms or getting hit by an enemy.
    - An overall very predictable behaviour.

    Can this relatively easy be achived with the controller? What would be the necessary steps for this?
     
  10. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    There is an option for movement style which can be PHYSICS_LIKE, DIGITAL or DIGITAL_WITH_SLIDE. Setting it to DIGITAL will give you the horizontal movement you desire. For your jump/fall there is a setting to control the max fall speed, the acceleration can be controlled by increasing gravity.

    This will probably give you the result you want, you may need just a little tweaking on the jump, which you can do via the settings or worse case via a few lines of code using the exposed velocity property.
     
  11. The_Daleatron

    The_Daleatron

    Joined:
    Nov 26, 2013
    Posts:
    43
    Hello happy xmas all,

    Just having a little problem here, When i use the heroanimator script my character wont walk only runs and plays the run animation when it should be walking, Do i need to edit the hero animator script for my walk to play, i have my walk in the animation list i really just cant figure out why its not working.

    Before when i used the model animator script, he walked and ran if i used shift, but my other animations wouldnt kick in for wall sliding and all that stuff.
    Now they all work with the hero one but my walk just isnt happening.
     
  12. bravery

    bravery

    Joined:
    Mar 26, 2009
    Posts:
    270
    Hi,

    I was wondering if I use the 2D platform controller to configure the player to aim always toward the mouse pointer?

    Also Wondering if we can configure the camera to follow the direction of the mouse.

    Maybe this game can explain more the requierd charater mouse bahviour?
    http://www.youtube.com/watch?v=zfHHgNjj5u4

    Please advise
     
  13. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Ther Hero Animator doesn't have a walk animation:

    Code (csharp):
    1.  
    2.     protected void Walk ()
    3.     {
    4.         if (playWalkAnimationsWhileSwimming || !controller.IsSwimming) {
    5.             animation.CrossFade ("run");
    6.         } else {
    7.             animation.CrossFade("fall");
    8.         }
    9.         CheckDirection();
    10.     }
    11.  
    Change the "run" to "walk" if you have one.
     
  14. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    There's nothing in the kit that does those things, but nothing in the kit to stop you doing it. I know a few people have implemented a similar system. If the shooting system is separate to movement then you don't really need to connect the code at all, maybe just a few changes to the animator or CheckDirection code to make sure the facing direction lines up with the guns direction.
     
  15. bravery

    bravery

    Joined:
    Mar 26, 2009
    Posts:
    270
    Hi JohnnyA,

    Maybe I will need more information form youside about how 2D Platfrom controller can really help in achiving such a result?

    Like does 2D controller have point at the mouse location script that I can utilize and based on that the animation will change to make the gun point at that place?
     
  16. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Sorry if I wasn't clear: the controller doesn't do anything like this, you would need to build this behaviour yourself

    All I was trying to say above is that you can use the controller for movement, and have another script for handling mouse look aiming and it shouldn't be too hard to have both systems working together as I know several others have done this.

    - John A
     
  17. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    To use 2D you have to switch over to the 2D versions of the classes have you done that?

    Note that the 2D ToolKit sample uses 3D physics. Its probably easiest to start from one of the Unity 2D samples and switch the sprites from Unity2D to 2D ToolKit.

    If you have done that I'm not sure what the problem is. I just did a quick test:

    1. Import asset in to new project.
    2. Import project settings form Porject folder. Unity crashes (hurray)
    3. Reopen Unity
    4. Open AlienSample2D Sample from 2DplatformController/2DVersion/Samples/
    5. Delete the box colliders from first few blocks, replace with edge colliders.
    6. Run it ... everything works.

    Does that work for you?

    - John A

    PS Ledge climbing will require BoxCollider2D it wont work with Edge Colliders.
     
  18. RyanNielson

    RyanNielson

    Joined:
    May 23, 2013
    Posts:
    24
    Ya,

    I deleted my post, but it seems you replied before I did so haha. Got it all working just fine after I noticed the 2D version of the Character Controller script. Thanks!
     
  19. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    One thing (bug) to note is that it still uses Physics.Gravity not Physics2D.Gravity in the 2D stuff.
     
  20. Dunkelheit

    Dunkelheit

    Joined:
    Sep 3, 2013
    Posts:
    81
    Hi Johnny,

    This asset look so great but I have some questions to do first off to evaluate my buying.

    - I'm using Physics2D.Linecast() to check if the player is on the ground. My ground is marked with "ground" layer is it easy to adapt this asset to use it or I can just ignore it and 2D Controller will take care about it?

    - Have you tested it with EasyTouch asset to support mobile touch?

    - I have never seen an example with a Xbox 360 joystick controller, why that? Can I adjust 2D controller to easily use any kind of joypad?

    Thanks for patience and keep it up. I need this questions for further buying.
     
  21. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    1. Controller has three layers: background (similar to your ground), passthrough, climbable. I expect that should map fine.

    2. No, although some people use it with EasyTouch. I can't comment specifically on EasyTouch integration but I can say that inputs are separated completely from the main controller and its generally not hard to create your own.

    3. As above. There are some controller samples floating about , if you know how to map inputs using Unity's Inputs then its a few lines of code to change the sample input in to a controller input.
     
  22. scrlklk

    scrlklk

    Joined:
    Dec 23, 2013
    Posts:
    8
    Hi JohnnyA,
    Is there any way to change the direction when controller is playing the idle animation? I want the player facing toward to the camera after turn the direction to 1 (right) or -1(left).
     
  23. BlankMauser

    BlankMauser

    Joined:
    Dec 10, 2013
    Posts:
    138
    How are collisions handled? Would it be simple to add another dimension so say, I have 3-4 layers in the Z axis that my character would be able to switch to, then restrict itself to the xy axis there and continue to collide properly with the polygons there?

    Also any word regarding compatibility with sprite factory? Thanks for your time.
     
  24. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Just edit your animation controller and in check direction set a different target rotation when the state == IDLE.
     
  25. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    They are raycasts, if you use the 3D colliders you can move the character in Z so it would collide on different planes. Alternatively you could change the backgroundLayer settings which would work even if they were all on the same Z plane.

    No official word on sprite factory as I have no idea what it is, however animators are separated from control logic. Out of the box it works with Unity 2D, 3D, and 2D ToolKit. Many people are using smooth moves and Orthello. To support a different renderer/animator you need to write the code that turns animation states into animations in your technology. Working from an existing example its usually very simple.
     
  26. Dunkelheit

    Dunkelheit

    Joined:
    Sep 3, 2013
    Posts:
    81
    What is coming to the next patch?
     
  27. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Previous page has a screenshot with some details.
     
  28. scrlklk

    scrlklk

    Joined:
    Dec 23, 2013
    Posts:
    8
    i changed the following code:

    Code (csharp):
    1.     protected void Idle (CharacterState previousState) {
    2.         animation.CrossFade ("idle");
    3.         CheckDirection();
    4.     }
    to:
    Code (csharp):
    1.     protected void Idle (CharacterState previousState) {
    2.         animation.CrossFade ("idle");
    3.         targetRotation = Quaternion.Euler (0.0f, 0.0f, 0.0f);
    4.     }
    but it didn't work as expected. The player still facing either left or right during the idle state.

    EDIT: Awww..i just figure it out, thank you so much
     
    Last edited: Dec 24, 2013
  29. ulutais

    ulutais

    Joined:
    Dec 6, 2013
    Posts:
    2
    Hello Johnny.
    I am using your controller and 2d toolkit.
    Ex: I have a fly kicking animation. I added this animation your sample 2dtoolkit project. Animation working but How can I move this animation ?
    My animation 2 second or 90 frames.

    public void flykick () {
    What is moving Code when animation finished?
    playerSprite.Play("flykick" + suffix);
    CheckDirection();
    }
     
  30. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    I'm not quite sure what you mean by "move this animation". Do you want the character to move a fixed amount when the animation plays? Or can the player still control the character while the animation plays? I'm thinking option 1 but correct me if wrong.

    Personally I'd say you need to extend the input controller for attacks. When the attack is active you stop setting input values (i..e ignore key presses). You use the controller exposed Velocity property to set the movement speed during the animation. This way you will still bounce of wall wont fall through platforms, etc. But the user can't override the attacks motion.
     
  31. bravery

    bravery

    Joined:
    Mar 26, 2009
    Posts:
    270
    Hi JohnnyA,

    Looking again for the 2D platfrom Controller and wondering wither I can have a similar behaviour of this one:

    http://www.youtube.com/watch?v=iR6V2oIESjQ

    It seams to me similar to the player controller you have, but I might be wrong, can you please tell me using your plugin out-of-the-box behaviour (without customization to cod) how much in % I can do something similar?

    Thanks In advance.
     
  32. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    I can't really put a percentage on it but that game looks physics heavy which means you would need to write additional code.
     
  33. Dunkelheit

    Dunkelheit

    Joined:
    Sep 3, 2013
    Posts:
    81
    Any chance to get support for joystick controller like Xbox 360?
     
  34. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Yeah its pretty simple to set up, my main issue is I dont have a PC to test on and I've heard it can be different. However a fair few people are asking for this lately, so I'll try and get it in by 2.1 (not sure 2.0 will be doable).
     
  35. Dunkelheit

    Dunkelheit

    Joined:
    Sep 3, 2013
    Posts:
    81
    Thanks Johnny for the quick reply, I have two questions more that concern about player behavior after I bought the asset:

    I'm trying to adapt the AlienChar prefab with previous char and I got some issues with it.

    1) When the player walks in front of a short wall he just "climb" it, if the wall is high enough he's behavior is what is expected. I have unchecked all possible options that suppose to cause it happens like in Climbing -> Auto Stick and Allow Climbing; and in Ledge Hanging -> Can Ledge Hang, Grab Only In Facing Direction and Auto Grab, but nothing changed and the char player continues automatically climbs the wall (without a jump effect, just "teleport" to the top). I've made a sketch to illustrate that.



    2) The second issue is about scaling. I have changed all alien sprites to fit my previous spreetsheet, so far so good. The problem I'm facing is the sprite scales up with my initial parameter (it suppose to be less than 1 for X and Y axis, original values) when the game render everything is normal, but when I start to walk down (and animations starts) my char sprites automatically scales to 1 for X and Y, I have no idea how to make it to be fixed in my original scaling values.

    Thanks and sorry about my english.
     

    Attached Files:

    Last edited: Dec 29, 2013
  36. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Dunkelhiet for number 1 can you send me an example, if you have ledge hanging off you can't climb a ledge.

    The code that does the ledge hang looks like this:

    if (ledgeHanging.canLedgeHang isLedgeHanging) {
    DoLedgeHang();
    }


    Theres no other call to DoLedgeHang() in the code base, and obviously that was guarded by canLedgeHang.

    Maybe something to do with collider config.


    For problem two in Unity2DSpriteAnimator2D the character is rotated by setting scale to -1,1,1 or 1,1,1.

    Two quick fixes, add your scaling on a game object between the Character and Sprite or update lines similar to this (in Unity2DSpriteAnimator2D):

    Code (csharp):
    1.  
    2. transform.localScale = new Vector3(1,1,1);
    3. ...
    4. transform.localScale = new Vector3(-1,1,1);
    5.  
    to be something like

    Code (csharp):
    1.  
    2. transform.localScale = myChachedScale;
    3. ...
    4. transform.localScale = new Vector3(myChachedScale.x * -1, myChachedScale.y, myChachedScale.z)
    5.  
    where:

    myCachedScale is a value you store in start.

    - - - -

    I'll make the fix for option number 2 in the next release.
     
  37. johot

    johot

    Joined:
    Apr 11, 2011
    Posts:
    201
    Hi JohnnyA,

    First off, thanks for a great product, bought a week ago and it has saved me alot of time.

    However I have a problem similair to that of Dunkelhiet, that is characters that "pop" up on the top of a platform. This is especially troublesome for pass throught platforms where if you don't create a really thin one all characters will pop up to the top of that platform when entering it from the side. And even if you make it really thin the problem is that a character can jump of that ledge, move to the side and pop right up again.

    The reason this is happening (from my testing) is most likely that the feet raycasts will find the collider when the character is "inside it", and so it will pop him on top of the platform.

    You can very easily simulate this by turning off all side colliders. When they are turned off the pop up behavior will show for all kinds of platforms.

    Note: I am using the RaycastCharacter2D controller.

    Any suggestions on how to fix this? Thanks!
     
  38. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    For normal platforms this shouldn't happen because your side colliders should never be inside your feet colliders, they should always be longer (and enough longer so that you don't pop). This is exactly what I meant when I mentioned that it might be a collider issue above.

    For passthrough platforms its an issue although there are a couple of fixes in there to help with that, when you jump you wont actually pop on to a passthrough platform you should continue drifting upwards, but there are circumstances where it can happen. At this stage you need to adjust your geometry to reduce the occurrences of this. I am looking at a better passthrough implementation, probably just an extra value which is the maximum speed and/or penetration required for popping on to a passthrough platform. This is very simple so no reason it wont make it to 2.0 (unless I forget, feel free to email me a reminder :)).

    EDIT: If you do have a really fast/oddly shaped character you may need to do add a few animated transforms to avoid the pop. The idea being that when you move really fast you move your side colliders out further and/or you feet colliders closer together.

    This means you can still get very accurate pixel perfect falling when you creep up to an edge, but when you are running you sacrifice a little bit of accuracy (which is not noticeable at high speed), in order to ensure there's no popping.

    90% of the time you shouldn't need this. Just make your sides a little longer.

    Also remember that your character doesn't need to be symmetrical... for example see the Hero character. When you fall off an edge its mostly to do with your back foot but you generally don't move backwards at speed... so you could make your character slightly asymmetrical with the back foot collider right on the back heel, but the front foot collider a little further inwards.

    Finally if you are stuck you can always send me your project and I'll set it up for you.
     
    Last edited: Dec 30, 2013
  39. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Also sorry if that reply sounded a bit dismissive, it wasn't meant to. I know a lot of these things aren't obvious or easy to setup, even I occasionally have trouble remembering which settings to adjust.

    This is one of the things I am hoping to address in 2.0.

    - - - -

    By the way talking of 2.0 I have officially allocated the 3rd to the 11th to work on it. Other than being tired from a crying newborn I have nothing else planned for that time. Thats more continuos time than I've ever spent on the package so I'm hoping I can knock it out of the park :)
     
    Last edited: Dec 30, 2013
  40. johot

    johot

    Joined:
    Apr 11, 2011
    Posts:
    201
    Thanks for your answers Johnny. No you don't sound dismissive at all so don't worry ;) But then I understand more about this. The thing when moving in the air however can be a problem even if you put the feet colliders "closer together" or at the heels, it depends on how fast your character can move in the air and how thick (heigh) your collider is.

    I've worked with a project similar to this myself a year ago implemented in the same way (with different rays), I'll look into this and see if I can find a nice workaround, i'll keep you posted if I find something interesting :)
     
  41. Dunkelheit

    Dunkelheit

    Joined:
    Sep 3, 2013
    Posts:
    81
    Hi Johnny and johot,

    I found something that can point us for one solution for this issue. In the RaycastCharacterController2D when it checks the ledge hanging or stun it moves to Y direction, so I've commented this snippet and the char stopped to jumps off to wall top, on the other hand he now just walking through the wall instead of just stop right there when reached, however this is the start point for us, I guess.

    Take a look on it:

    Code (csharp):
    1. if (!isLedgeHanging  (stunTimer <= 0.0f || stun == StunType.STOP_INPUT_ONLY || stun == StunType.STOP_INPUT_AND_X_MOVEMENT)) {
    2.                     MoveInYDirection(grounded);
    3.  
    I'll take a look more carefully under there, if I get something useful to fix it I'll let you know guys.
     
  42. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    You are getting a bit off track now. If ledge hanging is off you can never have isLedgeHanging == true, its set in one place only and its guarded by canLedgeHang. MoveInYDirection is the function that handles ALL movement in Y (jumping/falling/collision/etc), so you can't just comment it out.

    Send me a test case, there are many hundreds of users who don't have this problem so its more than likely configuration... if it is a bug, quite possible in the 2D code which is pretty new, I'm still not going to be able to fix it without the test case because I can't get it to repeat.
     
    Last edited: Dec 30, 2013
  43. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    That sounds very much like you are talking about a different issue which is already addressed in the controller. As per the documentation maxFrameTime * TerminalVelocity must be smaller than feet collider distance. If that is the case then you never fall through platforms or "snap" while in the air.

    The discussion about the heel colliders, was to do with vertical snapping caused by horizontal penetration. It only happens if you have a very fast character. Technically to avoid this you need to ensure that the length of the side collider minus the x position of the outermost feet collider is larger than maxFrameTime * runSpeed. This is a limit on the collider shape which only applies in the case of fast characters (and which is addressed using the techniques described).

    Both of these items are limitations on the collider configuration if they are adhered to there is no problem. I've yet to see a case where these limitations have stopped someone producing the movement they wanted and so I don't consider them issues.*

    The only thing I acknowledge as an issue is that if you enter a passthrough platform whilst falling you will snap up on top of it. I already have a fix for this (mentioned previously), and quick tests suggest it works fine. I'll get this in the next release unless I come across some kind of breaking test case.

    If you have a test case that shows otherwise please send it through.

    - - - -

    *The caveat would be that the 2D versions are new so I may have broke something when converting from 3D colliders to 2D.
     
    Last edited: Dec 30, 2013
  44. johot

    johot

    Joined:
    Apr 11, 2011
    Posts:
    201
    Ah okey thank you for this insights, i'll look into them.

    The problem I'm having currently is that if I create a large "pass through" platform and enter it from the side (the character is not falling or jumping, just walking straight into it from the side), I will pop up on top of it. You mean i should adjust the length of some of the rays to fix this? This is using the 2D raycast controller.

    One thing I did discover that might case issues (perhaps?) is that there is a difference between Physics2D raycasts and Physics (regular) raycasts. If you cast a ray using Physics2D and the ray starts inside the collider (for example the feet ray going from the center of the character and down to the feet), which happens when entering a big pass through platform from the side, it detects a hit and pops up on top. However if using the regular Physics raycast (for the 3d case) it will not detect a hit since those raycasts only detect hits if the ray does not start from inside the collider. Could that also cause issues? In other words the results with casting rays starting inside a collider are a bit different for the 2D and 3D case.
     
  45. Robiwan

    Robiwan

    Joined:
    Dec 29, 2013
    Posts:
    92
    I`m very new to Unity and currently trying to make my first game as a simple 2D platform to be released for mobile devices. And I`m looking into buying you asset but have a few questions:

    1) Can I easily create a simple three buttons touch controller, making one button left, one right and the third one jump. Keep in mind that I have very limited Unity and programming experience.

    2) Does it fully support Unity in 2D?
     
  46. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Yes that increases the pop (although not due to the side colliders passthrough platforms do not detect side collisions in anyway). However for pass through platforms they don't need any height at all...you can use a single edge. Of course visually you can do whatever you want.
     
    Last edited: Dec 30, 2013
  47. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    1.The touch controller can already do that, all you would need to do would be remove the images from up and down buttons. If you aren't using ladders/ropes then up and down don't do anything any way. Please note however that the kit is a player controller. It does have plenty of "Extra Features" like different platforms, levels, enemies, etc BUT being able create everything you want with zero programming is unlikely.

    2 Yes currently it supports both. Moving forward it will be Unity 2D Physics that is the main focus with 3D physics becoming decprecated .
     
  48. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Started design work on the update, not sure I'm going to be able to achieve all of my design in 2.0 as it was pretty ambitious, but there's always 2.x. As mentioned the core focus is still:

    1. More modular movement (theoretically you could use it for almost anything 2D :) )

    2. Easier to use (simplify ladders and ropes, standardize character setup, wizards, helpers, etc).
     
  49. The_Daleatron

    The_Daleatron

    Joined:
    Nov 26, 2013
    Posts:
    43
    sounds interesting cant wait to see it.

    I was wondering though, i got a tad confused the other day. I want to have some transitions in my game, so when i am and facing right or left and turn in the other direction it would play a turning animation and things like a stopping animation when you stop running etc. Now is it possible to do that with this package or do i have to mess around with the animator to get this ?
     
  50. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    For many cases you can use SLIDING as a stoping animation trigger. However more flexible is to do the following in the Idle() code on your animator:


    if (previousState == SLIDING || previousState == WALKING || previousState == RUNNING ) {
    // play your stopping animation
    } else {
    // existing code
    }


    (thats psuedo code but hopefully enough to illustrate). Of course if you are using mecanim you need to adjsut the Mecanim Animator too.

    For turning you would need a few lines of code ... in CheckDirection on the animator it sets the new direction (for example scale.x = -1 in 2D or setting a rotation target in 3d). Where it does this you could also play a new animation.

    I'm going to add a bunch more states to the controller in 2.0. My previous rule was don't add things I don't have an animation for... but I've decided its easier to just add a bunch so that its easier for users to make use of. I'll add STOPPING as a state between SLIDING and IDLE and CHANGE_DIRECTION or something similar for when character turns. Others to add will be: LANDING, HIT, CRAWLING, etc.