Search Unity

[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
    Just checked out your video, really cool looking game.

    Definitely some movement bugs in there though. Let me know if the above doesn't fix it. Also the sliding doesn't seem to fit the character/terrain, I'd suggest upping drag (and acceleration to accomodate this) so you get a tighter feel.

    - John A

    EDIT: I think I need to expand the doco on physics set-up, maybe some pictures of sample layouts and the like.
     
    Last edited: Jun 15, 2013
  2. Mike_011972

    Mike_011972

    Joined:
    Jun 8, 2009
    Posts:
    97
    Hi,
    I’ve been playing around with your kit and it really is very good, but I’m a newbie coder and I really don’t understand all the scripting for the platform stuff and general collision detection.
    I’m trying to knock up some code for collecting objects. I was hoping I could basically use the code from the Mario style block, where, when you hit it, it disappears, but that doesn’t seem to work (I’m using the hero scene). Could you give me some pointers please?
    Also, are there any tutorials that go into a bit more detail on this (I’m sure it’s really simple once you get your head around it, but I’ve got that learning curve starting out).
    I really love the fact that within 30 mins I had a basic level set up using Rotorz and had a decent, playable little demo to mess around with.

    Thanks,
    Mike.
     
  3. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    Thanks it's still pretty rough but I'm trying to build a sort of side scrolling loot centric ARPG. I was playing around with loose movement sort of in the style of Flashback, Out of this World, or old Prince of Persia but I don't think its a good fit either and I need to tighten the controls. Thanks for the input.

    Also, confirming that once I got my physics grid properly sorted out the movement bugs went away.
     
  4. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    If what you want to do effects movement then you should use the platform classes, if it doesn't you don't really need to. For example collectibles are more easily handled by adding a kinematic rigidbody to the character (along with a box or sphere collider), and then adding triggers to your collectibles. Just make sure your character/collider isn't in the background, climbable or passthrough layer.
     
  5. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Fix for ledge climb with tiled colliders is done. Also added wall slide. Video below shows an example, you can change the slide so that it varies from 1 (normal gravity) though to 0 (meaning you can cling to the wall without sliding). Also done is the "rough" fix for max rotation mentioned above.

     
  6. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Wall Sliding and Touch Control updates submitted - v1.5.1 - hopefully released in the next few days.
     
  7. Felix King

    Felix King

    Joined:
    May 2, 2012
    Posts:
    23
    Awesome! Looks great! Can't wait to get my hands on it :D
     
  8. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Thanks, hope you enjoy.

    One thing thats becoming apparent is that its really hard to manage all the settings. I'm thinking of creating a UI component where you can load settings saved as XML files. I can then provide XML files which are similar set ups to various popular games. To get a super meat boy like controller you just click load and select SuperMeatBoy.xml.

    Thoughts?
     
  9. parnell

    parnell

    Joined:
    Jan 14, 2009
    Posts:
    206
    That sounds awesome!
     
  10. Toad

    Toad

    Joined:
    Aug 14, 2010
    Posts:
    298
    That sounds fantastic.

    Could you make it so the settings can be saved to JSON files as well as, or instead of, XML files?
     
  11. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    I could, but the plan wasn't for this to be a runtime thing, so a bit of extra file size isn't much of an issue. Any particular reason you would prefer JSON format?
     
  12. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    Does the incoming version contain the mecanim animator controller? I wanted to take a look at your mecanim state tree
     
  13. robinball

    robinball

    Joined:
    Jan 1, 2013
    Posts:
    48
    Hey this is looking pretty good now. I've been toying with the idea of making an old school SNES style platformer and this looks like the best option.

    having presets for different game types sounds like a good idea to me.

    Does this work with the 360 controller? Or can it be easily remapped?
     
  14. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    You can map a controller easily yes, I've set up PS3 controller on mac in a matter of minutes. The main reason I havent done the mappings for all controllers is I dont have a PC to test it on!

    - - - - -

    Mecanim animator is not in the new version, I still have a few animations to add, and I need a new version of ledge climb. If you email or PM me I can send you the Mecanim package as it is now.

    - John A
     
  15. Voronoi

    Voronoi

    Joined:
    Jul 2, 2012
    Posts:
    589
    Your site/link seems to be down or the link is broken. I'd like to check this out.
     
  16. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Last edited: Jun 18, 2013
  17. Mike_011972

    Mike_011972

    Joined:
    Jun 8, 2009
    Posts:
    97
    Thanks for the help.
    Got the hero jumping around a rotorz tiled map, collecting stuff.
    Definitely one of the best scripts / kits I've bought.
     
  18. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Thanks I'm glad you like it.

    To everyone ... feel free to post your demos/samples/etc here. Would love to see what people are doing with the kit.
     
  19. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Unity is a bit slow on their approval for this one :s
     
  20. Player2D

    Player2D

    Joined:
    Feb 2, 2013
    Posts:
    50
    very very slow
     
  21. danish

    danish

    Joined:
    Dec 27, 2012
    Posts:
    10
    when i import 2d platform controller in unity 3.5.6 , during import it show fatal error window and unity crashes.........
     
  22. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    I'm just downloading 3.5.6 now (I'm currently on 3.5.5f3). In the meantime can you narrow it down to a specific area. For example try importing just the scripts folder.

    Regards,

    John A

    EDIT: Just confirming that I have no problem importing the package in to Unity 3.5.6f4 (on Mac). Contact me via PM so we can try and sort out which asset is causing the problem for you.
     
    Last edited: Jun 20, 2013
  23. BranDino

    BranDino

    Joined:
    Apr 12, 2013
    Posts:
    16


    One Error [ No definition for Scale ]. Its the code at the bottom of your script, I guess its to make sure the player sprite appears to be facing the correct direction. When I implement your script I get this error ------> : Assets/2DPlatformController/Scripts/Animators/SpriteAnimator2DToolkit.cs(156,25): error CS1061: Type `tk2dSpriteAnimator' does not contain a definition for `scale' and no extension method `scale' of type `tk2dSpriteAnimator' could be found (are you missing a using directive or an assembly reference?) --------------
    ----[btw: I renamed your script "SpriteAnimator2DToolkit.cs" so I could maintain JohnnyA's original to work with the other Spritemanager from Wiki] . ---- Thanks for creating this, today I was ready to import some animation for the first time and glad to see this just becoming available to support 2dtoolkit! Hope its a quick fix!
     
  24. msbranin

    msbranin

    Joined:
    Jan 19, 2009
    Posts:
    104
    Change the check direction function to this

    Code (csharp):
    1. protected void CheckDirection(){
    2.         // You might need to switch 270 and 90 for other values depending on orientation of your model
    3.         if (controller.Velocity.x > 0 ) {
    4.             playerSprite.transform.localScale = new Vector3(1,1,1);
    5.         } else if (controller.Velocity.x < 0) {
    6.             playerSprite.transform.localScale = new Vector3(-1,1,1);
    7.         }  
    8.     }
    Let me know if that fixes it for you.
     
  25. BranDino

    BranDino

    Joined:
    Apr 12, 2013
    Posts:
    16
    Yes that seems to have cleared the error. Thanks!! But I guess I am having a case of the stupids, as I am not sure how to arrange these scripts to enable the animation. This script gives me 2 variables populate, Controller and Player Sprite, for "Controller" I select "Character" which has the RayCast Controller Script component , and for "Player Sprite "I select the AnimatedSpriteRun. I created with 2dKit. No matter what object in my "Character Hierarchy" I attach this script too (what object do we apply this script too?) if I leave the "Controller" variable populated Unity will not run in Play mode and when not populated Unity Play preview starts in a paused state and I have to unpause it to play but no animation takes place. I guess I need to research the docs a little more to get these components talking to each other... if you have any guidance or if there is a prior forum post on this I would appreciate if you can fill me in. THink i will go watch "Man of Steel" it has been a long week!
     
  26. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Thanks for providing all this help msbranin.

    BranDino usually you attach an animator to a child of the character (which is the sprite or model). You are welcome to send me your project if you need detailed help.

    I can also add that I now have a nicely animated 2d (sprite) character to add to the kit and I will include some 2D samples in the next release. I also own 2DToolkit so it will definitely be one of the samples provided.
     
  27. BranDino

    BranDino

    Joined:
    Apr 12, 2013
    Posts:
    16
    thanks again for all the awesome support, I'll see if I can send you a basic sample of my project next week. (I did attempt to apply the modified animator script to child sprite of character and no bueno.... Have a good weekend!
     
  28. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    No probs, I've never used the above script although it looks right to me, and I know a few people have used it. Anyways once I take a look I''m sure I can help you out. Have a nice weekend too!
     
  29. suctioncup

    suctioncup

    Joined:
    May 19, 2012
    Posts:
    273
    I have applied this controller to my character, and it is working perfectly in almost every regard. If I jump while moving sideways (So in-air speed) I am really fast. Is there any way to cap this air speed?
     
  30. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    In your settings there is a jump->drag setting. Increasing that should hopefully give you what you are after.

    Technically JUMP speed is the same as WALK speed however if you are moving in the same direction as you were RUNNING just before you jumped, jump speed only has drag applied without being limited to WALK speed.
     
  31. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Still no approval from Unity ... grrr... PM or email me with your invoice number if you need the wall climb stuff ASAP :)
     
  32. Bast-I

    Bast-I

    Joined:
    May 28, 2013
    Posts:
    18
    First of all, thanks for this awesome asset! I got it a few days ago and am pretty impressed. But there are some things I didn't figure out, so it would be great if you could help me:
    ## Is it possible to have your moving platforms go in circles? I only figured out how to do diagonal or zigzag paths so far.
    ## Is it possible to have smoother movement around the turning point of your platform? Something like: platform slows down just before the turning point, then turns, then speeds up to normal speed.
     
  33. JohnnyA

    JohnnyA

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

    the platforms are only samples hopefully showing what can be done, but certianly not exhausting all possibilities.

    I'd suggest using something like iTween on a platform class to make it move in complex paths. I know someone is doing circles with that. I'll think about adding a simple circle moving platform the controller to, shouldn't be too hard.
     
  34. Bast-I

    Bast-I

    Joined:
    May 28, 2013
    Posts:
    18
    Thank you for your thoughts! So I will have a look at iTween, then.

    There is another, more basic thing that concerns me at the moment. You posted in this thread a solution to triggering the character's death and respawn (KillBox.cs and RespawnPoint.cs). I have difficulties in figuring out how to integrate these scripts in your demos. I put in both KillBox.cs and RespawnPoint as childs of box colliders respectively but I couldn't get it to work. (No errors but nothing happened with the character just standing on the killbox.)
    So could you please indicate how to apply these scripts to one of your demo scenes? That would be great!
     
  35. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Hi Bast, if you use the KillBox/Respawn scripts they should be a behaviour added to a platform (i.e. a box collider) in the background layer. Don't use a child, and make sure its in one of the platform layers (preferably background). The simplest way to do this is build you level as normal, then drag the scripts on to the platforms in your level.

    - - - -

    Another option to KillBox.cs you could use normal triggers.

    • Create a trigger and make sure its NOT in the background/passthrough or climbable layer. For example create a new layer called KillBoxes.
    • Make sure your character has a collider and rigidbody on it (again the character shouldn't be in the background, passthrough or climbable layer, I usually put it in a layer called Character). Make sure the rigidbody is kinematic.
    • Then add a script like this to your trigger (killboxes):


    Code (csharp):
    1.  
    2. public TriggerKillBox: MonoBehaviour {
    3.   void OnTriggerEnter(Collider other) {
    4.     RaycastCharacterController character = other.gameObject.GetComponent<RaycastCharacterController>();
    5.     if (character != null) {
    6.        RespawnPoint.Respawn(character);
    7.     }
    8.   }
    9. }
    10.  
    (Note I just typed that code in to the box here, might be a few errors).

    Here's a little sample that does that (get about 100m in to see a respawn point on the Easy level):

    http://www.kongregate.com/games/JNAMobile/escape-the-castle-beta
     
    Last edited: Jun 24, 2013
  36. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Stuff thats in progress - 2D Sample


    Stuff thats in progress - Mecanim

    PS I have no idea what Unity is doing with the update, maybe I should try to contact them.
     
  37. willeml85

    willeml85

    Joined:
    Dec 4, 2011
    Posts:
    23
    Great stuff, exactly what i need!
     
  38. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Update for Wall Slide approved (also include ledge hang support for tiled colliders).

    I have a few bug fixes to push out in the next release (nothing major :) ), which I will do within the week. I might try and sneak a few features in there too.

    - John A
     
  39. Flashist

    Flashist

    Joined:
    Jun 25, 2013
    Posts:
    11
    Hi everyone!

    Please, could someone help me in using 2d platform controller + 2dToolkit? Maybe someone have some tutorials or very simple "quick start" example?
     
  40. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Set up wise you need to:

    1. Create a 2D Toolkit sprite as a child of the character controller.
    2. Attach the 2D Toolkit animation to the sprite.
    3. Attach an animator like the example posted a few pages back or the one below.

    Here's a quick reference screenshot

    $SS.png

    Here's a sample animator ... very mush a work in progress:

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

    Flashist

    Joined:
    Jun 25, 2013
    Posts:
    11
  42. gruddlebug

    gruddlebug

    Joined:
    Mar 11, 2013
    Posts:
    65
    @Flashist

    This is very simple block push code...

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class BlockPush : Platform {
    6.  
    7.     // How hard the player can push
    8.     public float pushPower = 2f;
    9.  
    10.     override public void DoAction(RaycastCollider collider, RaycastCharacterController character) {
    11.  
    12.         if(collider.direction == RC_Direction.LEFT || collider.direction == RC_Direction.RIGHT){
    13.  
    14.             myTransform.rigidbody.velocity = character.Velocity * pushPower;
    15.  
    16.         }
    17.  
    18.     }
    19.  
    20. }
    21.  
    cheers

    evs
     
  43. Flashist

    Flashist

    Joined:
    Jun 25, 2013
    Posts:
    11
    2 gruddlebug:
    Thank you very much.
     
  44. Felix King

    Felix King

    Joined:
    May 2, 2012
    Posts:
    23
    Here's an early sneak peak at the 2.5D platformer I'm working on. It's a complete rewrite/refurbishment of an uni project I did a while ago. The extreme low-poly look is a design choice. A reminiscence to early 3D games like Mechwarrior, Star Fox (Lylat Wars) and Virtua Racer. The character will be replaced as soon as mecanim works with the controller.

    It looks a bit jagged on video - my hardware is to slow to record and run the game smoothly at the same time, but it runs fine on my 2 years old smartphone.



    Constructive criticism is much appreciated ;)

    Cheers,
    Felix
     
  45. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Thanks for posting that Felix, it looks really cool, can't wait to see the real main character in there ... if you want me to help get the mecanim controller going for your project in specific let me know (i.e. which animations do you need).

    Hard to be sure if its an effect of the video, but to me the fall speed looks a little too floaty, I'd think about increasing gravity and/or terminal velocity.

    Double jump should have another animation too, although thats probably more about getting mecanim going than anything else.

    Thanks for posting.

    - John A

    PS What do you think of the touch controls? They are so simple (much simpler than what I have done in the past) but for me they seem to work really well.
     
  46. Kersei

    Kersei

    Joined:
    Apr 29, 2013
    Posts:
    12
    I just bought this asset a couple of days ago and i have to say that it is awesome, but i have a little question and i think you could help me, i'm trying to do an animator script to get this controller work with the free asset Orthello2D and for now i can do the sync with the animations just right, but my problem is that when i move the character it plays the animation but at the same time do a extrange rotation and falls off the platform.

    This is my code:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class Orthello2DAnimator : MonoBehaviour {
    6.  
    7.     public RaycastCharacterController controller;
    8.     public OTAnimatingSprite mySprite;
    9.     void Start(){
    10.         // Register listeners
    11.         controller.CharacterAnimationEvent += new RaycastCharacterController.CharacterControllerEventDelegate (CharacterAnimationEvent);
    12.     }
    13.    
    14.     /// <summary>
    15.     /// Respond to an animation event.
    16.     /// </summary>
    17.     /// <param name='state'>
    18.     /// State.
    19.     /// </param>
    20.     /// <param name='previousState'>
    21.     /// Previous state.
    22.     /// </param>
    23.     public void CharacterAnimationEvent (CharacterState state, CharacterState previousState) {
    24.         switch (state) {
    25.             case CharacterState.IDLE: Idle(); break;   
    26.             case CharacterState.WALKING: Walk(); break;
    27.             case CharacterState.RUNNING: Run(); break; 
    28.             case CharacterState.JUMPING: Jump(); break;
    29.             //case CharacterState.FALLING: Fall(); break;  
    30.             case CharacterState.DOUBLE_JUMPING: Jump(); break; 
    31.             case CharacterState.WALL_JUMPING: Jump(); break;   
    32.             //case CharacterState.HOLDING: Hold(); break;  
    33.             //case CharacterState.CLIMBING: Climb(); break;
    34.         }
    35.     }
    36.    
    37.     protected void Idle () {
    38.         mySprite.Play("idle");
    39.         CheckDirection();
    40.     }
    41.    
    42.     protected void Walk () {
    43.         mySprite.Play("walk");
    44.         CheckDirection();
    45.     }
    46.  
    47.     protected void Run () {
    48.         mySprite.Play("walk");
    49.         CheckDirection();
    50.     }
    51.  
    52.     protected void Jump() {
    53.         mySprite.Play("jump");
    54.         CheckDirection();
    55.     }
    56.    
    57.     /*protected void Fall() {
    58.         animation.CrossFade("fall");
    59.         CheckDirection();
    60.     }
    61.    
    62.     protected void Hold() {
    63.         animation.CrossFade("hold");
    64.         transform.localRotation = Quaternion.Euler (0.0f, 180.0f, 0.0f);
    65.     }
    66.    
    67.     protected void Climb() {
    68.         animation.CrossFade("walk");
    69.         transform.localRotation = Quaternion.Euler (0.0f, 180.0f, 0.0f);
    70.     }*/
    71.        
    72.     protected void CheckDirection(){
    73.         // You might need to switch 270 and 90 for other values depending on orientation of your model
    74.         if (controller.Velocity.x > 0 ) {
    75.             transform.localRotation = Quaternion.Euler (0.0f, 270.0f, 0.0f);
    76.         } else if (controller.Velocity.x < 0) {
    77.             transform.localRotation = Quaternion.Euler (0.0f, 90.0f, 0.0f);
    78.         }  
    79.     }
    80. }
    do anybody have any idea why is this happening?, i don't know if i explain my problem right, and sorry for the bad english.

    NOTE: i commented some animations events because i don't have it yet
     
  47. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    A quick question is your animated sprite a child of the character controller? If not the above script will be manually rotating the RaycastCharacterController ... this should never be done.
     
  48. gruddlebug

    gruddlebug

    Joined:
    Mar 11, 2013
    Posts:
    65
    Hello,

    @Felix

    I Really like the graphics style and lighting

    Do you use any other plugins to achieve your effects or are they home grown?

    Once the character look and movement are perfected It should be great!

    I'll certainly get a copy - good luck


    cheers

    Paul
     
  49. Kersei

    Kersei

    Joined:
    Apr 29, 2013
    Posts:
    12
    Yes the animated sprite is a child of the character controller, but now that you mentioned it, you gave me an idea why is this not working.

    The problem was that this was rotating my animated sprite, so i just have to change the lines that switched the direction that the character was facing. So here is my animator for Orthello now running in case of someone besides me is using Orthello too.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class Orthello2DAnimator : MonoBehaviour {
    6.  
    7.     public RaycastCharacterController controller;
    8.     public OTAnimatingSprite mySprite;
    9.     void Start(){
    10.         // Register listener
    11.         controller.CharacterAnimationEvent += new RaycastCharacterController.CharacterControllerEventDelegate (CharacterAnimationEvent);
    12.     }
    13.    
    14.     /// <summary>
    15.     /// Respond to an animation event.
    16.     /// </summary>
    17.     /// <param name='state'>
    18.     /// State.
    19.     /// </param>
    20.     /// <param name='previousState'>
    21.     /// Previous state.
    22.     /// </param>
    23.     public void CharacterAnimationEvent (CharacterState state, CharacterState previousState) {
    24.         switch (state) {
    25.             case CharacterState.IDLE: Idle(); break;   
    26.             case CharacterState.WALKING: Walk(); break;
    27.             case CharacterState.RUNNING: Run(); break; 
    28.             case CharacterState.JUMPING: Jump(); break;
    29.             //case CharacterState.FALLING: Fall(); break;  
    30.             case CharacterState.DOUBLE_JUMPING: Jump(); break; 
    31.             case CharacterState.WALL_JUMPING: Jump(); break;   
    32.             //case CharacterState.HOLDING: Hold(); break;  
    33.             //case CharacterState.CLIMBING: Climb(); break;
    34.         }
    35.     }
    36.    
    37.     protected void Idle () {
    38.         mySprite.Play("idle");
    39.         CheckDirection();
    40.     }
    41.    
    42.     protected void Walk () {
    43.         mySprite.Play("walk");
    44.         CheckDirection();
    45.     }
    46.  
    47.     protected void Run () {
    48.         mySprite.Play("walk");
    49.         CheckDirection();
    50.     }
    51.  
    52.     protected void Jump() {
    53.         mySprite.Play("jump");
    54.         CheckDirection();
    55.     }
    56.    
    57.     /*protected void Fall() {
    58.         animation.CrossFade("fall");
    59.         CheckDirection();
    60.     }
    61.    
    62.     protected void Hold() {
    63.         animation.CrossFade("hold");
    64.         transform.localRotation = Quaternion.Euler (0.0f, 180.0f, 0.0f);
    65.     }
    66.    
    67.     protected void Climb() {
    68.         animation.CrossFade("walk");
    69.         transform.localRotation = Quaternion.Euler (0.0f, 180.0f, 0.0f);
    70.     }*/
    71.        
    72.     protected void CheckDirection(){
    73.         // You might need to switch 270 and 90 for other values depending on orientation of your model
    74.         if (controller.Velocity.x > 0 ) {
    75.             mySprite.flipHorizontal = false;
    76.         } else if (controller.Velocity.x < 0) {
    77.             mySprite.flipHorizontal = true;
    78.         }  
    79.     }
    80. }
    Is the same code but the only part that i changed is the CheckDirection function, thanks for the help and i hope you keep the great work. Awesome asset. And again sorry for the bad english.
     
  50. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Cool, glad you sorted it out.

    - John A