Ultimate 2D Platformer Controller in Unity (source code provided)
HTML-код
- Опубликовано: 20 сен 2024
- Source & game: github.com/Mat...
Extended source: / tarodev
Learn how to build an amazing player controller.
This Unity character controller is built using custom physics and incorporates all the hidden tricks to make it feel amazing. 2D player controllers can be difficult to get right, so hopefully this helps you along your way and gives your game a boost in productivity.
Features:
Variable jump height
Apex modifiers
Jump buffering
Coyote time
Clamped fall speed
Ledge detection
❤️ Become a Tarobro on Patreon: / tarodev
=========
🔔 SUBSCRIBE: bit.ly/3eqG1Z6
🗨️ DISCORD: / discord
✅ MORE TUTORIALS: / tarodev
The level of quality (video itself, presentation, quality of work, your humor) and the speed you’ve been putting content out is incredible. Thank you my fine sir.
Does that mean you have the source code? Because what's in the description is a different one that uses Rigidbody and a Capsule Collider instead of a box.
This is an incredible resource (and also the Celeste 101 haha), both for actual usage or just studying it. Thank you so much for providing this! Keep doing amazing stuff :)
Hopefully it can help some people out :)
@@Tarodev It will help so many people bro… Thank you. 🖤
hey papa alex, do you know if this code would work if i just straight up copied it into my unity project?
Do you have the code that doesn't uses Rigidbody and a Capsule Collider like he said in the video?
Short, straight to the point, open source and with a very nice prototype : Perfect !
Yeah but there is no source. Do you have it ?? That one has Rigidbody and a Capsule Collider in
I'm building a fully packed metroidvania and it already has almost everything you've implemented on this package, except for the ledge detection when jumping. So, I'm going to download it and give it a try! Thank you for your content, it's really great!
What's it called? Or did u give up after 6 months
@@good1742 It's called WIZ and I'm still working on the project. Since I'm solo developing it, it's taking a while lol But you can wishlist it on steam
@@bwulf wishlisted. looks cool
@@bwulf your game looks amazing
Did you manage to implement the ledge detection? I have been trying and I cannot use the code used here to nudge the player up when they barely missed the platform's ledge could you please help me?
Woah, Props to you to decide to give us a source for free. While you could easily sell this for some money. Mad respect.
This is awesome and I definitely plan on testing out this code soon but at 2:04 that has to be intentional that that arrow looks like a particular part of the male anatomy haha.
I don't need something like that at the moment but dude, it is perfect for 2D player controller. Keep up the good work!
2:03 LMAO!! Fantastic video once again and this just inspired me to create a game
Got the controller up and running in minutes. Feels great! I have to dig in a little as I'm finding he doesn't like slopes too much just yet.
Indeed, zero slope detection right now :P
It makes it easier to handle slopes of you use ray casts to check for ground🍻🍻
Just a heads up, if you are trying to use this character controller, the corner-nudging code doesn't work with tilemaps or colliders with complicated geometry. Instead get the nearest position of the collider you run into and go from there. (it needs some tweaks after that)
Definitely will have to be looking into this.. I'm not entirely understanding everything the code is doing yet, but this at least gives me a hint of something to look at.
Do you have the old code? I want to see if I can fix it
@@KuariThunderclaw I can do for you. For free... first thing on coding, you need to understand EVERYTHING in your code. Unless it's not yours
You channel is one of the finest in game dev tutorial now - short, precise and easy to understand.
I have followed some of your older tutorials - and you have improved a lot as a creator - over time.
Also would like to thank you for providing - all the resources and links in descriptions - and not creating a paywall for people to get your code.
Appreciate it.👌
Thank you for saying that. I like watching some of my older videos to see how I'm progressing. Glad somebody else noticed too
Do you have the code?? @Tarodev has switch it out
I have seen many platformer scripts and plugins, but this seems to be the best one I have seen yet. Going to try it out later, thanks so much like always :)
Great! This is what i was looking for
Absolutely brilliant, the most important mechanic being the wet splat sound ofcourse.
Oh yes 😉
This guy is legend himself. Finally an reliable advanced tutorial/resource to watch after Brackeys.
Thanks for saying that, brother 🙏
Hey! I watched your video about a week ago, I was desperately searching for a good 2D character controller whilst trying to learn Unity, and after some work I've managed to implement all the features you showed in your video using your code as an inspiration when I needed to, thank you so much for uploading this!
That's really cool! Thank you for publishing this. Also a really important thing in platformers is being able to see what's coming. I know this video is about the character controller but I just wanted to note it because it's important and that this has been a thing since the first Mario.
Basically create some invisible barriers where the camera will catch up to the player on the opposite side of it. If the player is moving to the right, place the character on the left side of the screen so the players know what's coming. In Mario I think they put you more in the centre of the screen, but it's pretty much all up to you.
Great tips. The camera was lacking a bit in this demo for sure. Especially on the drop zone.
May I recommend the Cinemachines plugin :)
It can exactly what you are asking for any significantly more. It is a free asset that Unity provide :)
Camera controllers are a science of their own - often underappreciated
This gave me a lot of insight on platformer polishement. You'r making great material, keep it up!
I actually logged into both my accounts to sub twice. This is a perfect tutorial. Short, sweet and resources provided with concise explanations. Thank you so much!
Lol damn bro, thanks
Yeah it would be a perfect tutorial if he had the source code and not something else
You my friend, is making the world a better place. Thank you!
I love your video, smooth, simple, and straight to the point.
I'd highly integrate your creation to the game we are making. If you would'nt mind, we'd love you to try it oneday when its finish.
Even the most basic scenario it's fun with those controls!
I recommended your channel to so many friends, and I won't stop! Great videos!
I appreciate the love, thank you 🙏
That thing sus 2:02 but this is a great vid!
Dude. That's some awesome community service. Kudos.
This is really cool. Great quick explanation
Quickly and easily you've become my main channel to watch on RUclips above anything else. I'm going to learn so much heading into my 2nd year as a Game Dev, so much more to learn but am just getting started. All your content is amazing, much thanks :)
Much appreciated 🙏
Do you have the code? Because @Tarodev switch the code to use Rigidbody and Capsule Collider.
Its incredible how much info can fit in a 3min video.. congrats
I just found this and i love it and how customizable it is and though it's a little bit slidy (at least for me) it's amazing and i'm gonna try incorparating some of these on my own when i am better at using unity
Thank you!
I'm always trying to learn what makes movement more satisfying.
2:02 sus doodle.
Fantastic resource! Just found your channel today and I'll be deep diving through all of this fantastic content.
Do you have the source? Because he changed the code
Am I the only one to have a pervert brain ? 2:02
Despite that moment I lost attention, the video was sOo instructive. ^^
Good job, man !
I just see a helpful arrow :)
it reminded me to that episode of south park when Randy forecast the weather.
I stopped at that moment to read the comments, looking for "Is nobody gonna talk about the..."
@@ericjorgearnezinochea9679 Haha!
Wow. Just wow. Definitely sharing this.
Wow I've been working on platformer games for yyyyeeeearsss and am hearing some of this for the first time tysm
This is so perfect! The controls looks smooth and perfect
what a fricking amazing channel !! so happy my friend told me about this
I just subbed from a different video and I gotta say thank you for this one as well, but I just can't get over that squishy sound when it lands after a jump, it is vile how absolutely sloopy it sounds😆
Especially the slow mo splat :D
This is great, Taro! I'm curious, why did you code your own collision system instead of using Rigidbody, CharacterController, or just Unity's collider + OnCollision() functions?
Doing it this way gives you total control. I've made plenty of controllers in the past and always using RB. This was the first real crack at a full custom physics controller and it's turned out by far the best with only about 2 days effort.
A good example is the ledge detection. That would have been quite a lot harder using built-in collisions I think.
@@Tarodev that's a good point, thanks for your fast answer!
@@Tarodev Hi, I have been playing around your controller code a bit and realize the same thing. I agree using the built-in collision is a hazzel, but this is what happen:
1. when I want other entity to detect the player using rigid body, I can't
2. if I put a rigid body or colllider on to the Player, the player is stuck and can't move.
3. so the other entity has to implement the same custom collision method. Meaning, extract the collision part of the code and create a seperate class, and then have the player detect by if other has the collision class..
4. eventually leading the same hazzel....
so... basically if we were to use your custom made collision code, its like once go black, can't go back kinda deal...
or.... is there a better way of doing this? Am I doing something wrong? I'm trying to have 2 players to bump onto each other.
Thanks~ Cheers~~
@@bluzenkk Simple, You put colliders on the players, you disable all player-environment collisions using layers.
This way you can collide with stuff without making everything go crazy.
@@bluzenkk hassle
I've made physics like this several times, but the hardest thing IMO is velocity transfer from lifts. It Fs everything and stuff breaks around :D
My team just added this to our game! The way we got working without much hassle was by giving the lift a reference to every object that needs to receive its momentum. Then, whenever the lift moves, it can also call the movement functions of all of the objects that also need to move.
This system can allow you to do other cool things as well. For example, if you give the player a separate “fixed velocity” component from the regular velocity, you can store the lift’s velocity so it can then be transferred to the player once they jump off. To get this working, the player will also need to store a reference to the lift so when they jump off, the player script can access the lift and clear the lift’s reference to the player so the lift stops trying to move the player.
Brilliant video! Really excited to give this a go! You’ve done an amazing job continuously contributing to this until today (I can see you’re still active in the comments)
I do my best 😅 Enjoy the controller!
This is awesome!
Also, for speedrunners: turning off Clamped Fall Speed should be a little faster :D
Yes you're right! Might be harder to make that curved fall though :P
@@Tarodev If we are using Celeste as a case study they allow you to dash downwards taking away your dash of course however they gain downward momentum equal to that of the dash momentum almost instantly.
Man… controls look perfect. Thank you bro. 🖤 Will help me a lot.
2:02 I see you. Yes, I'm burning through all your videos. Thanks again!!
Woww😳. Awesome dude. Keep it up and Thanks for making this.
my favorite of all these invisible tricks is clamped fall speed, it just feels so great to be able to land more precisely when your fall speed is clamped
It's one of the lesser loved ones, that's for sure. But remove it and it's absolute chaos.
Dude this is an amazing resource, I've played platformers for years and I never knew what "coyote time" was but the second you said the words I knew what you were talking about.
Tricks of the trade 😉
I'm showing your channel to all my friends, keep it up
Appreciate it Paulo
These contents are real unique and important to know. I hope you keep creating them.
Beautiful! Thank you so much for sharing this!
And for those who would rather make your own, try to look into some of the key words mentioned and making those mechanics one by one.
It's a great way to learn character controllers but physics and other things as well.
wow that guy is building a portfolio haha ^^ nice project and thank you very much! this is such a great resource for starting game dev!
Now I am hyped to revisit my paused astro platformer project! 🙏
maybe adding the ability to modify acceleration and deceleration the way you want for making some ice maps for example so the player slowly slides on the platform, still it is an ultimate controller and i love it
This is an invaluable resource, thank you!
You're most welcome
actually insane, great resource!
This looks awesome! Thanks man!
Bro much appreciated, Been on my journey as a solo dev and this is an invalubale source, amound others. Thank you
I just now updated the free version of the controller. Go check it out :)
Dude thanks, this is exactly what I was looking for
Bro I really needed something like this (and not made like 7years ago), as I am studying an tinkering with Unity.
This is both extremely good for me to use and focus on other aspects or treat as research material.
+Subbed
Subscribed. Excellent video. Frewt movement. That cude felt so smooth so proffesional.
Everything is good on this video. Like everything. Not only the thing I was searching for.
That's a top notch resource right there
Good shit. Became a patron for the extended controller (worth it)
adding these kinds of mechanics to games are what makes them enjoyable in my opinion. you can be a casual gamer and just do the basic stuff or someone very competitive who wants to really take advantage of every little thing and figure out all the mechanics and how to best use them. Apex Legends is a perfect example for this. You dont *need* to learn all the fancy movement tricks but if you do learn them and practice them and master them you can really distinguish yourself from the rest.
Very new to unity, thanks for the gift, should help me get motivated to do and learn more.
Awesome, well done! Thank you so much for sharing!
Yo thanks dude this is awesome, subbing.
It's great to explain all concept you can find in a controller, I used to use Sebastian Lague Platformer Controller implementation like base to implement my own and I found thoose tricks by myself later. And you give me some tricks I didn't have yet like vertical edge detection to correct movement. Thank you.
I'm becoming a fan of this channel. Awesome stuff! :D
Slowly winning you over?
@@Tarodev Yes, stuff that you are doing is high quality and well explained. Thank you, keep up doing great stuff :)
this is amazing, very appereciated
this is a true legend, thank you for providing the tutorial
You're welcome brother
He doesn't even give the source like he says he does. It's different code.
I would like to create a challenge room that's almost impossible in the case of Hollow Knights White Palace and see if ease of movement adds to the experience or detracts from it. There should always be pros and cons when dealing with movement, attacks, upgrades and abilities so you can feel like there's some form of accomplishment or it would feel like handholding to a suffocating extent
Sounds like my kind of game
Have you by any chance saved the old code? @Tarodev has replaced it with something that has nothing to do with the video
This is maybe the best Unity 2D platformer video on RUclips right now. And that you can get its source for free and use it yourself in commercial projects... dang.
People like you drives the community further
keep up the good work
Thank you so much for the awesome, and concise examples. Extra kudos for sharing the source code. What a god 💯
Awesome Work!! Awesome share!!
OMG the unity 2d controller that is ACTUALLY worth downloading. Nice work, good research, and thank you.
Would love to see more additions such as being able to jump up through floors above you and land on them, think smash bros, also down jumping that lets you phase though floors below you
This is incredible! Thanks so much for making this. I just got into Unity and just could'nt get the character jumps feeling good at all. Amazing!
I almost don't want to go download this just to try constructing it myself...
Good stuff Taro, loving the content.
Too bad if you didn't downloaded it because I'm looking for it. He switch the code of the video with another.
This is epic thanks!
Omg, this is some god tier mechanics. Saved and Subbed
Happened upon this video by chance and so glad that I did. Concise, to the point and the fact that you're sharing this source code is very cool. +1 sub
Do you have the source code? Because the code he has right now is not the code he is using on the video
Ill love to check that out!
Thank you for the video! no nonsense and to the point. Thanks for the source code as well!
Actual poggers. Thanks!
Wow that looks awesome!
wow this is so fluid not using unity but learnt alot from the logic
Another level of depth to this is - speedrun controls - for e.g a forward down dash after a small jump lets u cover huge gaps in Celeste taking fractionally lesser times as compared to a normal jumping reaching its apex and so on .. game development is a deep deep rabbit hole ..
wow this is amazingly informative. And in just under three minutes! thanks so much :)
2:04 the sketch reminds me about something
This looks awesome, thank you for this!
Thanks for the controller, very helpful video and well made!
Please never delete this video
Dude, this is awesome
Very nice controller feels really nice. I tried it for my project which contains slopes and this controller breaks wonderfully :D
Hah yeah, needs a bit of work to utilize slopes
short, effective and USEFULL perfect video 10/10
This was a big help to me, thanks!
this video is incredibly well made, i'm currently making a subway surfers-esque game and yet this is still really useful information for my jump mechanic despite the two games being insanely different - just shows how absolutely brilliant this video is🫡
What an absolute chad, makes an epic player controller and gives it out for free.
Spreading the love brother
@@Tarodev exactly what we need in this community , you have now gone in the ranks of brackeys (if not higher) and other amazing game devs on youtube, you legend
@@fishbox385 Damn bro 😂 Thanks
Dude this is just a huge amount of work you gave away for free. Thanks so much