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. Mad_Fox

    Mad_Fox

    Joined:
    May 27, 2013
    Posts:
    49
    Hi Johnny, im having problems creating a simple rotating/spinning platform, i've made simple rotating platforms scripts in the past, but my character just stand there and dont react to the rotation because i dont quite understand how the platforms scripts do it, Thanks!
     
  2. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    If possible do no edit the RaycastCharacterController. If you have to try and keep your edits as minimal as possible.

    I expect most people will write their own inputs and animators and consider the ones I have provided to be samples. Thats why they extend some base class. So create your own for both these (obviously you can copy the existing ones as a baseline).

    Anything in extra features is subject to change without notice (although realistically I'll probably just add things not change the old stuff). Still its probably easiest to create your own versions (copies) and put them in a different folder with a different name or namespace.
     
  3. mjdonizetti

    mjdonizetti

    Joined:
    Jul 2, 2013
    Posts:
    5
    I really want to see what you made, sir.
     
  4. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Video will be posted on my youtube channel today sometime (subscribe if you havent... pretty much every update and idea goes there before it gets released :)). ( http://www.youtube.com/user/JNAMobileHidden )

    I'm still not as far along as some of the other people working on this, but I think I have some nice ideas that will tie in pretty well with the controller (e.g. place spikes on the platforms and they will move around with the terrain as you move it, and when you hit play if the character runs in to them they will take damage).
     
  5. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    I helped a few people with this in past, I'll try dig up the code and include it in the next update. What exactly are you having trouble with? The main things to do are to use the platform mechanism and ensure the object you parent to has uniform scale. There are definitely some tricky bits when it comes to smoothly falling off the platform, but you should be able to get 90% of the way pretty quickly.
     
  6. mjdonizetti

    mjdonizetti

    Joined:
    Jul 2, 2013
    Posts:
    5
    I checked your youtube channel at the moment I read your comment about it here. :)
     
  7. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039

    Recorded a voice over but my microphone was off :s ... at the end I go through a list of planned features but given you can't hear me heres a quick summary:

    - Attach platform behaviour to terrain (i.e. ice is slippery, lava burns you).
    - Add objects to terrain (e.g. spikes).
    - Make it also work in 2.5D
    - Ability to set an angle and only apply surface if its within this angle.
    - Overlays like the surface for sides and bottom.
    - Get some textures to show things off better!
     
  8. kauaiBlake

    kauaiBlake

    Joined:
    Feb 28, 2013
    Posts:
    36
    Hey johnny, thanks for the tips, I will try not to mess with the RayCastCharachterController if I can help it. :) Hey one more small question, is it possible now to have some sort of crawling when you crouching and standing still, then move sideways, or is this something that would have to be added?

    Oh, and +1 for wanting swimming :). I think we will have to do that at some point, be great if you did it for us heh.

    Thanks again for a great resource and all your help. You rock!

    -Blake
     
  9. p6r

    p6r

    Joined:
    Nov 6, 2010
    Posts:
    1,158
    Great platform creator !!!
    Is it a new asset or included in a next release of your Platform Controller !?!

    6R
     
  10. AMO_Noot

    AMO_Noot

    Joined:
    Aug 14, 2012
    Posts:
    431
    Does anyone know if there's a function you can call to change the direction that your character controller is facing through code? Just modifying the scale of the sprite from 1 to -1 can give the appearance of it, but it can cause some wonky behavior as well.

    Seconded, still very much anticipating it.
     
  11. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    If you want your character to face a different direction you should add your own direction checker which works out the direction using whatever mechanism you want. For example you could create one that determines the facing direction based on the position of the mouse. Doing this you could also expose a method SwitchDirection or something similar which forces the character to face the opposite of the direction it is currently facing.

    EDIT: For a sample see the Hero character which has its own direction checker (used in this case because the Heros colliders change depending on the direction it is facing).
     
  12. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    I'm having problems to add enemies to my game! I added a RigidBody to my Sprite (child of a BasicCharacter), disabled Use Gravity, added a Box Collider to it, and my enemies also have Box Colliders on it, but the collisions (between the players and the enemies) are never detected! =(

    Any advice of what should I check?

    Just checked 2DToolKitSample and the collision with the Coins and Mushrooms also seems to be not working on that example. Any advice?
     
  13. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Check layers applied to the characters/enemies and also the layer collision settings (preferably whilst game is running). Make sure one of your colliders is a trigger. Are the enemies working in the samples that have enemies (not the 2DTK ones)?
     
  14. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    @Wagenheimer... any luck?
     
  15. AMO_Noot

    AMO_Noot

    Joined:
    Aug 14, 2012
    Posts:
    431
    Cool, thanks for the tip, John.
     
  16. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    Not yet! =(

    I found the problem with examples, it was because I modified the Original Prefabs!

    But I could not make my collisions to work yet! It should be something very lame from me!

    There is some way I can send you my project to you check it?
     
  17. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Yes my email is in the instructions file, just export a unity package with whatever you need in it.

    - John A
     
  18. parnell

    parnell

    Joined:
    Jan 14, 2009
    Posts:
    206
    Hi Jon,

    Sent you a small animation update.
    thx
    B
     
  19. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    Thanks for the help!! Now the collision works! =)

    Just a question, I broke my player movement. How to create a new movement class?

    I created a new class :
    public class RoninMovement : RaycastCharacterInput

    But when I click on Character Input to select it nothing appears, I can't select it... What am I doing wrong?
     
    Last edited: Sep 18, 2013
  20. gamesbyangelina

    gamesbyangelina

    Joined:
    Jun 23, 2013
    Posts:
    20
    Is there any way to purchase this direct from the developer? Unity's regional pricing almost doubles the cost of the plugin for me. (USD -> EURO)
     
  21. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    If you are okay to make payment before delivery and to use PayPal then we can do a direct sale at 33 Euros (which is store price plus a little to cover paypal fees at current rates). I'll provide you a once off link to download, and you will have to contact me directly (via the support email) for upgrades.

    In other words I don't have a process in place for this but I'm happy to help as long as you are willing to drive the process (email for updates, etc).

    If you think that is reasonable contact john@jnamobile.com and we can sort it out.

    Hope that helps,

    John A
     
  22. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Seemed to work fine in your sample scene. Make sure you have the RoninMovement attached to a gameobject in the scene (for example the character).
     
  23. gamesbyangelina

    gamesbyangelina

    Joined:
    Jun 23, 2013
    Posts:
    20
    That's so kind of you to offer. I'm going to put in for the whole store price anyways, so you don't have any extra trouble. Really touched that you made the offer though :)
     
  24. gamesbyangelina

    gamesbyangelina

    Joined:
    Jun 23, 2013
    Posts:
    20
    Just popping in to say I spent today porting over my game to use this and chuck out the old controller, and it's so great. So, so great. I had hit a huge roadblock on my game and this completely blew it away and let me get on with actually making games instead of fixing stupid stuff. Thanks!
     
  25. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Glad its helping you... please leave a review in the asset store if you can.
     
  26. BakaRecca

    BakaRecca

    Joined:
    Sep 18, 2013
    Posts:
    2
    Hi JohnnyA!

    Great tool you've made! I love it!
    I just have a little bit of problem. I'm giong for a retro type 2d sidescroller plat former game. And I hate rotation sprites.
    So the SLOPE-question I'm having is that how can I use your tool to go up and down a slope without rotation the sprite?

    I know how to disable it. But then it only works perfectly with going up a slope. If I'm going down a slope the player goes a little bit off it and does the fall animation and lands on the slope again.

    So is there a basic and easy sollution to use your awesome slope-system but never to rotate my sprite graphic?
    Like every other old 2D platformer as Super Metroid and stuff.

    Because it works perfectly with the rotation. And I want to keep that awesomeness but not rotation my sprite. Like in this picture here even though the sprite is a little bit modified. I just want to have my full run animation in the X value and just move up and down perfectly without to ever have to rotate my sprite and don't have the skipping and falling glitches when you're running down a slope.

    Have read all this thread now not to really understand or see the solution.
    The CharacterMotor script works great with slopes up and down, but the controller is flipping my character very badly.

    Sorry for this long post and my bad english.

    Otherwise you're tool is the greatest!

     
  27. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    The rotation allows the character controller to work out what to do on slopes. You don't need to have that represented visually. The simplest thing to do is to add a script to your sprite object that sets its rotation back to zero before rendering.

    If you want to do nicer things with your sprite (e.g. different animations) then you can read the controllers rotation from your animator script and override the default animations.
     
  28. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    By the way been a while since I've had a review on the asset store (despite lots of good comments elsewhere). These are really useful for me, so please add one if you have the time.

    Cheers,

    John A
     
  29. AndrewKennedy3D

    AndrewKennedy3D

    Joined:
    Aug 1, 2013
    Posts:
    4
    Hey Johnny, great script, I have had a lot of fun using it so far. I've noticed a problem concerning vsync and framerate.

    Due to issues with Vsync, it has the potential to screw up the result of time.deltaTime. This can result in jittery character motion or even result in the character walking backwards in some instances. I think it's due to the way that friction/drag is calculated, and I've found the error mostly when the acceleration and drag are at fairly high values. Keep in mind that I am not a very experienced programmer, so I'm only ~90% sure that this is the cause of the problem. I've searched around the thread and haven't seen it mentioned yet.

    Do you have any plans to address this? I can get around it by moving the code from the "LateUpdate" function to the "Update" function, but of course then this leads to unreliable input detection.
     
  30. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    How to jump and fall faster?

    - Fall Velocity seems to not have effect to me!
    - If I change Jump Velocity if Jumps Higher (but not faster).

    How to achieve faster Jumps and Falls?
     
  31. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    This is suprising to me, becasue it was adressed in an earlier version. This doesn't mean it hasn't slipped back in becasue of another fix though. I'll check it out over the weekend. If I can't repeat it will be useful if you can send me a Unity package and some notes on your project settings.
     
  32. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Physics.gravity drives the acceleration during the fall, terminal velocity (in movement settings) drives the maximum speed the character can fall at. Fall velocity is the speed that the animation event transitions from IDLE or AIRBORNE to FALLING.

    It is in the code (and the generated API docs) but I understand that its hard to find and can be a bit confusing

    Code (csharp):
    1.  
    2.     /// The terminal velocity in the y direction.
    3.     /// WARNING: If this is too large you will be able to fall through platforms. Make sure maxFrameTime * terminalVelcoty < feetCollider.distance.
    4.     /// </summary>
    5.     public float terminalVelocity = -12.0f;
    6.  
    7. ...
    8.  
    9.     /// <summary>
    10.     /// The velocity required before the fall event replaces the airbourne event (negative number).
    11.     /// </summary>
    12.     public float fallVelocity = -1.0f;
    13.  

    As for jump velocity it definitely controls how fast you jump... if you are jumping higher thats becasue you are jumping faster. However to get that really zippy platformer feel I find the best bet is to increase gravity and then adjust jump velocity. I also like to tweak time... it might be "cheating" but it gives the best feel :)

    I've had a few requssts for an easier system for setting these things up but its a lot of change for only a small benefit (you generally only need to tweak things a few times).
     
    Last edited: Sep 20, 2013
  33. BakaRecca

    BakaRecca

    Joined:
    Sep 18, 2013
    Posts:
    2
    Hey! Thanks for the tip!
    I have tried it out with a lot of different types. But I don't get what I'm searching for.
    Pretty new to Unity but have been making games with other platforms for serverals of years.
    So could you or anyone tell me where to write the code and what code I need for this to work?
    Do I need to store the current rotation and give it back after the rendering. I'm totally lost here. =(

    Ofcourse I will rate it! right away!
     
    Last edited: Sep 20, 2013
  34. AndrewKennedy3D

    AndrewKennedy3D

    Joined:
    Aug 1, 2013
    Posts:
    4
    Thanks a lot, you're really going out of your way to address everyone's concerns which I very much appreciate, you've got yourself another review on the app store in the near future.

    I'm currently getting around the problem by disabling Vsync and lowering the maxiumum allowed timestep in the project's Time settings. It's not a perfect solution, since it could cause quite a slowdown on some machines, but it's the only way that I have seen to get around it thus far.

    I look forward to your response!
     
  35. BTStone

    BTStone

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

    do you have plans for something like a pendant/rope bridge-feature? If not, is it possible to realise this with your Plattform-Scripts?
     
  36. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Hi mate, thanks for this, found the issue. Has nothing to do with vsync as such. A few releases ago I changed the drag calculations to be less physics like but easier to work with. An unnoticed consequence of this was the equation which calculates actual drag isn't linear. This only becomes apparent as you approach the boundaries (i.e. low frame rate with large drag). On my machine you can't see it with VSync On but you can with Vsync every second blank.

    Will definitely fix this, but it might be a little while as I need a solution that doesn't impact other users too much. In the meantime may I ask why you need your drag values to be so large?
     
  37. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    I think I'd just do that in Unity physics (string of unbrekable hinge joints) and then have a platform script that applies a small force on to the rope bridge when the character is standing on the platform. Will have a go at it sometime this weekend.

    - John A
     
  38. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    @AndrewKennedy_2

    Have a fix available, send me a PM or email. I can't release it yet as it needs some more testing.
     
  39. gamesbyangelina

    gamesbyangelina

    Joined:
    Jun 23, 2013
    Posts:
    20
    I've got a bit of an awkward question. I have two types of platform that I previously had on separate layers, because I don't want them to collide with one another. However, I want them both to be solid to the player.

    The RaycastCharacterController only uses a single integer by default. I can hack it to use multiple layers but I wondered if there was a more elegant solution to have multiple layers be background/solid to the player?

    EDIT - Actually that information isn't quite right. Let me clarify it. Three types of block: A, B and C.

    A and B are both on the Blocks layer. I need them not to collide with each other, so Blocks/Blocks is false in Physics Settings. The Blocks layer is my BackgroundLayer for the Player.

    I need C to collide with blocks, but also with the player. I can't put it in the Blocks layer or it won't collide with blocks. I can't put it in another layer because it won't be in the BackgroundLayer. Is there a good solution to this?
     
    Last edited: Sep 21, 2013
  40. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Usually most of the background doesn't collide with each other (its static). Accordingly you can set the background layer to not collide with itself. For special blocks just have two colliders on different layers.

    That said this is not great if you have a LOT of blocks that need to collide with each other.

    Having multiple background layers is something on the agenda so I can probably get that in to the next update (out in a week or so).
     
  41. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    Sorry, but there is more questions! =)

    How to Jump Down?
     
  42. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    There's a sample script called PassthroughPlatform which shows how you can add "jump down" to a passthrough platform.

    - John A
     
  43. gamesbyangelina

    gamesbyangelina

    Joined:
    Jun 23, 2013
    Posts:
    20
    Please don't worry about it just for me! I just hacked a version of RaycastCharacterController (I know it's not advised! I just wanted to see if it would solve my problem ;) and it definitely does the trick. The object is nice and solid, but doesn't mess with any of the other blocks. Your code is really well engineered, this change barely affected any other files. I think I had a few minor changes in SimpleHealth, SetUpPhysics, and one of the AI segments.

    This really impresses me more and more each day. Left a review today too! Thanks again.
     
  44. AndrewKennedy3D

    AndrewKennedy3D

    Joined:
    Aug 1, 2013
    Posts:
    4
    You haven't had many reviews recently on the Asset Store; due to the amazing service I received I had no choice but to write one of my own. I haven't seen anything but a perfect score from people who know what they're doing, and it's easy to see why. Thanks again for everything you've done, I can't wait to see what new features this project has in store for the future!
     
  45. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    Thanks for the review mate, very kind words!

    - - - -

    On to the shameless self promotion, finally submitted some of the 2D stuff I wanted to put on the asset store...



    $Screen Shot 2013-09-23 at 6.42.57 PM.png

     
  46. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    827
    I suppose this would also allow for (sideways) climbable walls rather than just the ledges at the top?
     
  47. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    You have to add climbable layers to the walls you want to be climbable. But that reminds me I was supposed to be adding wall climb to the wall stick behaviour.
     
  48. Xaikira

    Xaikira

    Joined:
    Jul 24, 2013
    Posts:
    8
    Is there a way to detect when the player leaves a Platform? I need to change controller settings (along with animations) when the player steps on the platform and reset them once the player leaves the platform. Is it possible to just call a function once when the player steps on it and another when the player leaves? I've been using the DoAction void but this calls every frame and won't register when the player leaves.
     
  49. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    There isn't but you can emulate it pretty easily using DoAction() with a little timer (when the player is on the platform reset a timer to 0.1f (for example)) also set a bool. If the timer expires (decrement it in Update and check if smaller than 0) whilst bool is set you left the platform.

    See the decaying platform for an example.

    If you want a more generic test of the player leaving a platform (i.e. not specific to a certain platform), you can use the character state and/or character y velocity.

    I'll try and add this in an update as I can see where it would be quite useful.
     
    Last edited: Sep 24, 2013
  50. MBoffin

    MBoffin

    Joined:
    Mar 29, 2013
    Posts:
    15
    My only complaint is that this package has such a generic name that it's near impossible to search for things relating to it. If the Unity forums had the ability to search within a specific thread, that would help a little bit, but this single, unsearchable, mega-thread is really hard to use as a support line when looking for answers to questions.

    That said, thanks for the work you're doing on this package. It's really well written and very, very useful.