Search Unity

[Released] 2D Platform Controller

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

  1. mousse

    mousse

    Joined:
    Oct 3, 2013
    Posts:
    27
    So I got preview 2 imported into a new unity project and a bunch of weird things are broken.. such as not being able to shoot or climb ladders.. input issue? the sprites are missing in the ice level, etc.

    anyone else having this problem?
     
  2. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    I haven't tried preview 2 package on a fresh project maybe when I removed the cartoon FX stuff I accidentally removed some other stuff. I'll try to take a look tomorrow.
     
  3. chris200x9

    chris200x9

    Joined:
    Mar 22, 2014
    Posts:
    8
    This package has a lot of stuff that I don't need (it's way too advanced for me). I am trying to use it as a simple character controller though, I attached the raycastcharactercontroller2D and simple character input script everything works great except I go about halfway deep into the ground and just vibrate up and down a bit there. I can still move and jump, any tips?
     
  4. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    As per instruction start with the prefabs, particularly if you want something simple. Its much easier to change the sprites/models/colliders on the prefab than to create a new character from scratch.

    - - - -
    In other news lots of time off over the next few weeks so should hopefully get some good updates in to Platformer PRO.

    Has anyone else had the issues with the preview mentioned by mousse?
     
  5. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    Hey Johnny,

    I sent you a mail with a little problem regarding 2DPC ;)
     
  6. mousse

    mousse

    Joined:
    Oct 3, 2013
    Posts:
    27
    I'm on the latest version, and I tried 3 different computers for fun and profit. I also tried changing that initial box to 2d/3d default setup for the project. Same results.

    Is it not broken for you? I wonder if it's version at that point.
     
  7. Xevoius

    Xevoius

    Joined:
    Sep 26, 2012
    Posts:
    25
    Vibrating usually occurs when two different Raycasts are fighting eachother. If you are going halfway deep into your ground that indicates to me you don't have the feet colliders configured properly. You most likely need to adjust the "offset" for them. When you are playing your scene start tinkering around with the feet collider values. I seem recall my sprite looking like it was slightly overlapping my ground until I adjusted it.

    ...oh and if your ground is not flat then you really need to tinker with the spacing of the feet colliders otherwise you can get an edge up between two of them and get that same jittery type behavior.
     
    Last edited: Apr 17, 2014
  8. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Did you? I don't think I saw a ticket from you...
     
  9. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    It is broken for me, none of the project properties were added so all the layer settings are missing. I'm guessing when I took the Cartoon FX out of the export package, Unity decided I no longer wanted to export project settings either.
     
  10. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
  11. Claymore

    Claymore

    Joined:
    Oct 17, 2012
    Posts:
    158
    HI Guys,i need you professional help there. So i sent e-mail to support@jnamobile.com to get preview version and nothing happened,it sent me back massage who says : Your request (143) has been solved. To reopen this request, reply to this email. So i replied and again nothing happened,i've been waiting for 24 hours to get reply with "Preview 2" But nothing :( Can anyone please help me?
     
  12. nonameu

    nonameu

    Joined:
    Apr 8, 2014
    Posts:
    18
    hi guys one more question regarding simplehealth script. I have a gameobject as parent of three characters. I can swap the characters depending on the value of health. in the parent object I have the simplehealth script atached. the question is which controller should I atach in the Inspector? I believe to have this working I need to somehow atach all three controllers at same time? Maybe an array?
     
  13. nitekrawler

    nitekrawler

    Joined:
    Dec 8, 2013
    Posts:
    13
    I put in a ticket about 3 days ago for Preview 2 as well (request 137) and hadn't heard any word just yet. I wouldn't be surprised if working out the above described bug with project settings is causing a delay.
     
  14. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Nitekwarler check your spam, I responded to that ticket days ago. Although it will have the layer issues as there is no preview 2.1.

    Claymore the only request I have that I haven't responded to with the preview is one that has no order number attached. I've asked twice for the order number to be attached. Not saying that is you, but its the only one I can see.

    For everyone please note you can always send me your ticket number if it has been a few days* with no reply, its rare that I wont to reply to a ticket within a day or two (even if it is just to say "Hey I have your ticket but I wont be able to look at the issue until the weekend").

    - John A

    * Please wait at least 48 hours.
     
    Last edited: Apr 19, 2014
  15. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    The health should be attached to the active character yes. When you switch your characters you should be able to do something like:

    yourhealth.controller = yournewcharacter;

    of if you only have a game object reference

    yourhealth.controller = yournewgo.GetComponent<RaycastCharacterController>();
     
  16. chris200x9

    chris200x9

    Joined:
    Mar 22, 2014
    Posts:
    8
    I'm trying to pause my character from another script so I have other setup as my raycastcontroller2D, I couldn't figure out how to easily do this so I'm just stunning him to pause him. Below is the code I'm having trouble with.

    other.ForceSetCharacterState(CharacterState.STUNNED);

    The above doesn't seem to work however I can call other.Stun(1000) and he will be paused but I don't need the character paused for a certain length of time. I want to pause him and unpause him via state changes according to events.

    Any help is appreciated, thank you.
     
  17. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    use character.controllerActive for a complete pause.
     
  18. nitekrawler

    nitekrawler

    Joined:
    Dec 8, 2013
    Posts:
    13
    @JohnnyA

    Thanks for the heads up. With gmail's new layout the spam folder is now hidden through a few options.
     
  19. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
  20. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Got it, but I think the video was too big as I cant see any attachments.

    - John A
     
  21. lightassassin

    lightassassin

    Joined:
    Mar 29, 2013
    Posts:
    45
    Heya Johnny!

    I have been lurking for awhile, glad to see the new update is progressing nicely, and you've even done some other packs... you're a mad man especially with that baby to take care of. When is number two baby coming? =D

    So, just to let you know, I still exist and I am still using 2D Platform Controller. After I missed my planned dates the decision was made to go from a very simple mobile compatible version to a desktop (console maybe, hopefully, please Mr Sony/Xbox) version with far more features and using 3D for art.

    Biggest fun is the 4 player co-op both local and networked. 4 players on one PC with controllers is so much fun! The networking has been my biggest gripe by far, but the controller plays nicely and only requires some minimal things to be exposed for simple access (for those curious I use TNet with custom inter/extrapolation setup and time stamps, choice of server including listen and dedicated on Win/OSX/Linux).

    I am no longer completely solo, my brother is now doing a lot of the 3D modeling, rigging and animation. While I took crash course in Blender to convert it over to 3D (I am doing all the characters, as my previous experience in Drafting in 3D CAD helps). Using the 2D art works as concept art is great and allowed all the gameplay features to be set in stone before the full conversion. Textures are a combination of the two of us with some cool little tricks we've learned.

    Animation is now handled with Mecanim which mostly dynamic based on in game locomotion/actions except for some state flags (attacking, hang/climb ledges etc...). This has also helped heaps with the networking as not much has to be passed anymore (original one passed animation states... bad idea).

    I wrote my own custom attacks, heavily modified the AI controllers for a base AI controller and added special collectables that could be used for special states. Everything is integrated with 2DPC or derived from and has saved heaps of time.

    For those reading this and thinking is 2D Platform Controller worth it? It is! This asset is fantastic! I could never have made so much progress so fast on my own. While I personally went through some struggles it was never due to the controller (only my inexperience), it only made things easier, and I imagine the new Pro version will be even better (I am way too far down the rabbit hole to even be tempted into using it at the moment).

    I will post my first gameplay videos here soon. I am just finishing up a teaser trailer with the new characters and game logo but it doesn't show anything 2DPC related. So in a couple of weeks, I'll have a gameplay trailer ready and posted (got lots of marketing to do and lots of media to annoy Yay!).

    Side note: I do have some bugs but I don't think they matter until after your rewrite. I have fixed/worked around a couple (there isn't many) and others don't effect my use of the controller.

    TLDR: 2DPC is awesome, buy it, use it, customize it and love it. Plus my game is coming... soon!

    Cheers,
    Ben "Renown Wolf"
     
  22. mousse

    mousse

    Joined:
    Oct 3, 2013
    Posts:
    27
    Should I just try and get preview 2 working however I can then? I'm not a unity expert by any means so if you have any advice on getting the input for climbing and shooting working again that would be cool.

    Otherwise, good luck and I can't wait for beta!
     
  23. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Its great to hear from you, I have thought of your project a few times and was wondering how it was progressing. Glad to see its moving forward and can't wait to see the teaser.

    Regards,

    John A

    PS Baby number two is already here so its all a bit busy at the Avery household :)
     
  24. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Well if you name the layers and reselect them that will get some stuff working pretty quickly (you can name the layers anything, they just need to be named for a couple of editor scripts). But still it took me a bit of stuffing around to get everything working and I know the product so it might be a bit too much to expect someone else to do it.

    I'll aim to do a preview 2.1 release, with maybe 1-2 extra features and the proper settings exported. Maybe tomorrow, but more likely next weekend.

    Regards,

    John A
     
  25. nonameu

    nonameu

    Joined:
    Apr 8, 2014
    Posts:
    18
    Hi Johny

    suddenly I'm getting this error

    NullReferenceException: Object reference not set to an instance of an object
    SetUpPhysics.Start () (at Assets/2DPlatformController/Scripts/Utility/SetUpPhysics.cs:26)

    didn't change anything in physics

    edit: nevermind just figured out :oops:
     
    Last edited: Apr 21, 2014
  26. mousse

    mousse

    Joined:
    Oct 3, 2013
    Posts:
    27

    You are the man, thank you.
     
  27. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    Hey John,

    I sent you a link to the video instead of the videofile itself :)
     
  28. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Did you get my reply?
     
  29. Ac6057

    Ac6057

    Joined:
    Mar 22, 2014
    Posts:
    5
    tk2dspriteanimator could not be found error
    sample are not playble pl help
     
  30. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    That class is used by the 2DToolKit sample. You shouldn't unpack that unless you own 2D ToolKit.
     
  31. Mad_Fox

    Mad_Fox

    Joined:
    May 27, 2013
    Posts:
    49
    Hi Johnny, super simple question, im on V1.8, any quick way to change falling speed without touching the gravity in physics?
    The "Fall Velocity" inside the Jump tab on the controller doesnt seem to change anything in my game and in your samples, im doing something wrong?
    Thanks!
     
  32. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Fall velocity is the speed at which the animation for falling plays (its there to stop the character constantly falling on slopes and tiny bumps).

    Terminal velocity is the hard cap on velocity in the -y direction.

    Gravity is used to affect falling acceleration as you have surmised. You'll need to update code if you want to do something else, there's a method called ApplyGravity() which applies the gravity, change Physics.gravity.y for your own value.

    Alternatively if you don't want to touch the code you could just add a little acceleration each frame in another script using character.Velocity (for example see how jetpack script works).

    PS if you read the HTML doco (or comments in the code) you can get more insight in to each variable:
    $Screen Shot 2014-04-27 at 10.36.41 am.png
     
  33. vicdelacroix

    vicdelacroix

    Joined:
    Apr 13, 2014
    Posts:
    6
    Hey Johnny, will you be including some 2.5D scenes with platformer PRO? All I've seen so far is 2D, that's why I ask.
    Thanks!
     
  34. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    I'm using 2D for my initial development as its generally easier to see the movement state (for example to check if there are animation issues), plus creating mecanim animators is not a lot of fun. But yes PRO will have 2.5D samples of all the main features.
     
  35. Mad_Fox

    Mad_Fox

    Joined:
    May 27, 2013
    Posts:
    49
    Jhonny, you point me in the right direction, i didnt want to mess with the gravity of the project, so i briefly changed your "float" script to suit my needs, everything is working fine now, thanks!
     
  36. nonameu

    nonameu

    Joined:
    Apr 8, 2014
    Posts:
    18
    Hi again Johny

    quick question, the EnemyBounceAndFallInput script. If I do Debug.Log(direction) it always returns true if the direction of the enemy is -1. I need to check if the enemy is facing right or left.

    -1 always true. 1 only true if facing right
     
  37. KidSicarus

    KidSicarus

    Joined:
    Feb 3, 2014
    Posts:
    35
    Hey, Johnny.

    I too am in need of changing fall velocity, as I find the physics too floaty, but I am not sure how to easily go about this. I have tried changing gravity via Project Settings and Physics (not Physics2D) but that just clamps down on the upward velocity. If I add a RigidBody2D to the character it pulls it underground upon landing. And I don't have a jetpack script and not sure how to edit the float script.

    What would be the very best way to go about this? I find this very important to be able to nail down the control feels.

    Would it easy for you to write a simple solution that could be easily implemented in this package for everyone without much skill?

    Also, is it possible to jump higher the longer you hold down jump? Complete documentation eludes me.

    Thank you!
     
  38. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    The normal process if increase Physics.gravity to fall faster, increase jumpVelocity if you want to jump higher. Note that the fall speed is limited by terminalVelocity.

    - - - -

    To jump higher the longer you hold down jump set the jumpHeldTime and the jumpHeldVelocity:

    $Screen Shot 2014-04-30 at 1.06.22 pm.png

    This is from the documentation included in FullHTMLCodeDocumentation.zip. Drag the file to your desktop (or another folder outside your project) and expand it. Its HTML and includes a search function.

    - - - -

    If you want more control over the jumps you are diverging from the core of the script. You have to write a couple of lines of code. The Float.cs script is an example of changing velocity when falling. To make jumps "floatier" you would need to do something similar:

    Code (csharp):
    1.  
    2.     public float floatFactor;
    3.  
    4.     void Update () {
    5.         if (controller.Velocity.y > 0) {
    6.             controller.Velocity = new Vector2(controller.Velocity.x, controller.Velocity.y - Physics.gravity.y * floatFactor * Time.deltaTime);
    7.         }
    8.     }
    9.  
     
    Last edited: Apr 30, 2014
  39. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    I'm not quite sure what you are asking... if direction ==-1 the character is moving left, if direction == 1 the character is moving right. The direction certainly changes to reflect the movement direction, you can see it in the inspector.
     
  40. GadoBelial

    GadoBelial

    Joined:
    Feb 22, 2014
    Posts:
    9
    Hello again.
    I have 2 problems that i want to share with you.

    Firstly, if there is someone who know a way to control how much the characters jump , depending on how long you press the jump button.
    I already know that there is a jumpframe time and jump held timer, but i can't make it work as i want, when i put a jumpframe and jump held time, looks like when the button is pressed for enough time the character "floats" when jumping...is weird.

    I was asking myself if there is a way to apply the velocity.y with a Time.DeltaTime so when the player just tap the buton the character doesn't jump so high, but when pressed for longer time the character begins to reach little by little his maximun jump height.


    Secondly, did anyone knows a good way to use diferent animation depending on where the character is facing(it's a 2D sprite character, using animator) , this is because our character (the protagonist) it was desinged with on mechanical arm, and the other one is a normal arm. So we have the classic problem that when the character is facing in diferent directions, the mechanical arm change position due the controller just flipping the sprite :S

    thanks in advance for your help.
     
  41. Xevoius

    Xevoius

    Joined:
    Sep 26, 2012
    Posts:
    25
    My main character holds items and then need to be faced a specific direction like a hammer or a torch. When the player picks up the object, I make the object a child of the player. I then track its location during the animation cycle each frame by editing the animation itself and updating new hand coordinate variables. The last tricky part is when I deparent the pickup object as it wants to flip back to the same direction it was facing before I picked it up because once parented it takes on the flipped nature of the player.

    So I basically have an enum DirectionFacing that both the player and its pickup items use. When I deparent the item and it's DirectionFacing is not the same as before I picked it up, I flip the Sprite before the next Update. This way the object maintains its flipped state correctly whether held by the player or not.

    Get it? :)

    Let me know if you want some code or a clearer explanation.
     
    Last edited: Apr 30, 2014
  42. Xevoius

    Xevoius

    Joined:
    Sep 26, 2012
    Posts:
    25
    One other thing...

    You can always manage the arm independently and flip it when you want and not have it tied to the parent object by doing changes to it in LateUpdate(). Upate() and FixedUpdate() won't look good and will give some laggy type behavior.

    I just had to do this for a workaround for some other asset I am using.

    Something like this and then sprite flipping is not tied to the parent.

    Code (csharp):
    1.  
    2. void LateUpdate()
    3. {
    4.         // flip if necessary
    5.         if (someObj.currentDirectionFacing == DirectionFacing.LEFT   currentDirection == DirectionFacing.RIGHT ||
    6.             someObj.currentDirectionFacing == DirectionFacing.RIGHT  currentDirection == DirectionFacing.LEFT)
    7.         {
    8.             FlipSpriteImageYAxis(transform);
    9.             currentDirection = someObj.currentDirectionFacing;
    10.         }
    11.  
    12.         // match the position
    13.         transform.position = new Vector3(someObj.transform.position.x, someObj.transform.position.y, someObj.transform.position.z);
    14.  
    15.         // match the rotation
    16.         transform.rotation = someObj.transform.rotation;
    17. }
    18.  
     
  43. GadoBelial

    GadoBelial

    Joined:
    Feb 22, 2014
    Posts:
    9
    Thanks Xevoius for your reply :D

    That sound like a good work arround. But its not about fliping the arm, its more like how to change entirely the position of the arm in the animation.

    How you handle when the Character sprite have a mechanical left arm and a normal right arm.
    If the character is facing to the right, the mechanical arm need to be at the background of the player and the normal arm at the front.
    When the character face to the left, the mechanical arm need to be at front and the normal arm at background.

    And this needed for all the animation the character have (idle, run, jump, fall, airbone etc..).

    attaching an pic, explaning my problem.


    $armProblem.jpg
     
    Last edited: May 1, 2014
  44. JohnnyA

    JohnnyA

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

    Regarding holding jump... that's pretty much how it works, minus the ability to specify a fixed max height (this in Platformer PRO though). If the button is affecting the jump for too long reduce the time. It does take a bit of experimenting with all four values (including gravity and the main jump force), but generally you can get the right feel. Generally I first get the minimum jump right (i.e. without any jump held time), and then play with jump held time until happy.

    For your sprite it seems like just having two separate sprite sets would be the way to go. Obviously flipping the arm and positioning it in front isn't going to work right either... surely the inside of the mechanical arm looks different to the outside of it?

    The animator code is only a guide, most projects will write their own animator based on the existing code. In your case I'd just swap the sprite sheet (or if using Unity 2D do a mecanim animator override) based on the change direction value. Effectively you only need to replace the one line of code which responds to the animation direction change.

    - John A

    PS If you have a support request please use the support channels (button on the web site r the support email address).
     
  45. Xevoius

    Xevoius

    Joined:
    Sep 26, 2012
    Posts:
    25
    If your robotic arm is really complex and you don't want it stuck to your body sprites (within the same image) then I would say just use the SpriteRenderer's sorting layers and you can set it to be on top of the player or behind the player depending on the layer and which direction the player is facing.

    Feel free to contact me directly if you want to chat more about this as I would be happy to share my thoughts.

    Here is how I manage my player's hand location when he is holding items on a per animation frame basis.

    $15qyft0.png

    Notice how you can adjust variables for each animation frame. I suspect this will be useful for your arm.

    Thanks for the jump info Johnny. I think I am going to go back and try and tune mine up a bit.

    Gado, I don't want to fill this thread up with replies so shoot me a message if you want to continue discussing. The most straightforward way would be to just have two animation sets for all actions for each direction he is facing. I went down the flipping route.
     
    Last edited: May 1, 2014
  46. GadoBelial

    GadoBelial

    Joined:
    Feb 22, 2014
    Posts:
    9
    Thanks again Xevious and Johnny.

    well, the arm of my character is really detailed...and have different looks from left to right side, so i can't just flip it, i need to change it completely from one animation to another.

    (here a low res pic of my char)
    $SidesArm.jpg
    Look how the perspective of the character change when face different directions....and this is the case with all the animations :(

    I'm thinking maybe the animator override could make the trick, but im not sure, because there isn't much information about how to use it.
    Any advice?


    Btw, i'm going to try what Johnny said about the jump, to see if works :p

    Thanks again.
     
  47. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Sent a response to your request.
     
  48. AMO_Noot

    AMO_Noot

    Joined:
    Aug 14, 2012
    Posts:
    433
    Did a cursory look through the thread, but not sure I saw it:

    Johnny, has anybody requested or provided a sample for Crush detection? (i.e. detecting when getting squished between moving platforms and walls, etc.)
     
  49. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Not sure, but the basic idea is pretty simple (although does require a controller edit, would be pretty hard without one). Add variables to track maxRight and maxLeft penetration when the controller loops through the collisions in MoveInX. If both are above a threshold ... squish!
     
  50. AMO_Noot

    AMO_Noot

    Joined:
    Aug 14, 2012
    Posts:
    433
    Thanks for the tip! Will give it a go. :D