Code Class - 2D Player Movement in Unity

  Рет қаралды 24,822

AdamCYounis

AdamCYounis

Күн бұрын

(reuploaded to fix an error in the edit of the previous version)
Heya Pals!
Welcome to a first in a series of video tutorials for Unity Development. We'll be covering all kinds of content in the series, so be sure to subscribe and check the playlist for future videos.
Music: Rifti Beats - Chocobo & Chill [Gamechops.com]
Chapters:
0:00 - Intro
1:00 - GameObject Setup
4:00 - Simple Top-down Movement
10:50 - Preparing your Project for Art Assets
12:38 - Sidescrolling Movement with Basic Physics
14:51 - Friction and FixedUpdate
16:41 - Ground Check
20:27 - Platforming, Acceleration and Jumping
25:55 - Summary
26:37 - Outro
27:03 - Post-Credits Code Review
----
Become a Patron at / adamcyounis
Twitch: / adamcyounis
Twitter: / adamcyounis
Tiktok: / adamcyounis
Discord: / discord
Download assets and games from the stream at uppon-hill.itch.io/
Later, pals!

Пікірлер: 71
@Vesrayech
@Vesrayech 3 ай бұрын
TIL that Adam is not a 'never nester.' As a more intermediate dev I really enjoyed this. I like the way you handle drag and friction through code rather than solely with the inhouse physics engine. It was refreshing to have more of a deep dive into base movement, rather than trying to fit as many 'features' into the video like double jumps and coyote time.
@AdamCYounis
@AdamCYounis 3 ай бұрын
I feel like the nesting helps me appreciate that there's a condition there. Indentation exists for a reason, and I don't see the harm in one extra tab. Though sometimes I make an exception if the function is particularly complex with many steps and lots of return cases. The early return can be considered step one.
@Notreal76
@Notreal76 3 ай бұрын
You have a gift for teaching. It comes so easy to listen and follow.
@marissamorris778
@marissamorris778 3 ай бұрын
It's pretty amazing how quickly you turned this around for how high-quality of a video this is! Thank you so much - looking forward to the rest of the series. :)
@zacccore
@zacccore 3 ай бұрын
Thank you for doing a series like this. I actually really appreciate how you explain everything, and the pacing is very good imo. I definitely came to your channel for your pixel art content, but I am 100 percent on board for more of these unity videos!
@franskeeh
@franskeeh 3 ай бұрын
Finally managed to catch one of your livestreams this morning and now seeing this video, perfect timing because I wanted to start unity today! All of your stuff is incredibly inspiring, and I've been wanting to dive into things myself. And while I have experience in front-end coding, most tutorials I've encountered skip the stuff that makes you actually *understand* it. Thank you Adam!
@jweare333
@jweare333 3 ай бұрын
Great video! I love your dev journals, but I really truly enjoy your instructional videos for Unity and/or pixel art. Thanks!
@CharlesA.
@CharlesA. 3 ай бұрын
I was looking forward this one. Thank you so much Adam. We really appreciate you bro !
@jtacua7822
@jtacua7822 3 ай бұрын
YEEEEEEEAH I'VE BEEN WAITING THIS KIND OF TUTORIALS FROM YOU! THANKS!
@Ilgar1
@Ilgar1 3 ай бұрын
I literally was searching for this and I saw your upload. Bless you
@jeremieboulay4805
@jeremieboulay4805 3 ай бұрын
As a casual user of Unity, this video really helps me to see good usages of Unity. It conforts me on some way I'm going things but also shows me features I'm didn't know about or used without really get the purpose of it. You show really really good practices on the fly where most of the tuto online are just g straight to the point but in a super dirty way. Without considering scalability, code refactoring or real implementations. So thanks!
@ELF_Productions
@ELF_Productions 3 ай бұрын
I love to see the explanations on the coded version of friction and acceleration. Awesome tutorial and well explained
@Ebenchadnezzar
@Ebenchadnezzar 3 ай бұрын
This was soo helpful, please continue this series!
@louiscorbett4834
@louiscorbett4834 3 ай бұрын
Great tutorial, I wish I had these style tutorials 5 years when I first began my gamedev journey! I love that you explain each of the various Unity fields & code inputs rather than just glossing over them! Thanks Adam!
@funteav3437
@funteav3437 3 ай бұрын
Adam, your coding tutorials are a game-changer! Your teaching style is spot-on, making complex concepts easy to grasp. I'm hooked and genuinely hope you keep the series going. Your gift for teaching is making a real impact, and I'm excited to learn more. Cheers!
@tombandiera9083
@tombandiera9083 2 ай бұрын
Works great, thank you ! It's really nice to have someone covering both coding, art and game design on the same channel as i'm interested in both subjects. In addition, your videos are of high quality and you are very pleasant to listen to in the way you explain things. Good luck with Insignia by the way, can't wait to buy it :)
@stefans3780
@stefans3780 3 ай бұрын
these are incredibly useful and understandable, you're really good at explaining things Thanks!
@JimmyCeeTV
@JimmyCeeTV 3 ай бұрын
Just the info I was looking for, and very well explained. More like this please 🙏
@globes179
@globes179 3 ай бұрын
Nice, would love to hear more in the later vids
@NeatGames
@NeatGames 3 ай бұрын
The detailed explanations are awesome :D
@sitrusjo
@sitrusjo 3 ай бұрын
Love the video! As someone who loves your videos but is working on a 3d game it's great to get some variety from pure pixel art tutorials
@solodevelopmentstudio7645
@solodevelopmentstudio7645 3 ай бұрын
Thank u very much, this will help alot. I'll start watching these videos a couple of months later but thanks a ton.
@clickmeifyoudare
@clickmeifyoudare 2 ай бұрын
Just discovered this series and it’s exactly what I needed. Great content from what I’ve watched so far!
@mehmetberkayyalcn9009
@mehmetberkayyalcn9009 Ай бұрын
Thank you . Your video is better than most of the others and it helped me.
@esvanquiroz1996
@esvanquiroz1996 2 ай бұрын
Thank you so much Adam for making this. As a newcomer to making video games, this is incredibly helpful. I am really interested in more top down pixel art game development videos. I findd a wealth of content for platformer games but for top down, sadly, not so much. Keep up the amazing content and I look forward to future videos. Best of regards man.
@teddysundin2992
@teddysundin2992 Ай бұрын
This is awesome! Exactly what i was looking for!
@truongthan6593
@truongthan6593 3 ай бұрын
Yesss, i need this so much! Thank youu
@iam.thomas
@iam.thomas 2 ай бұрын
This is gold, thanks!
@simonhughes1324
@simonhughes1324 3 ай бұрын
Thank you Adam.
@CoderFromTurkey
@CoderFromTurkey 3 ай бұрын
Thanks for the video!
@alejmc
@alejmc 3 ай бұрын
Great video. That section at the end: I’m often bumping into where to do the check test itself (i.e. if the input has anything meaningful to do any logic)… so sometimes I end up doing it twice if I wanted to use that “CheckInput” function in a larger and more expensive method, so, I would do “if there’s input, do x/y/z/w/u/p things, else skip”, but CheckInput itself still checks if there’s any input. Could return the results of the first check input boolean but then it starts getting over-engineered quick…
@Kdoe0_0
@Kdoe0_0 2 ай бұрын
my gosh thank you!
@seanrendall5495
@seanrendall5495 2 ай бұрын
Gotta say, this is a lot better than the code ChatGPT wrote for me. Ai coding has a long way to go, still.
@ty-xq7bl
@ty-xq7bl 3 ай бұрын
Best guide for 2d
@TK-dz2vu
@TK-dz2vu 28 күн бұрын
Great Tutorial. Some things sadly still go a bit over my head, but I understood a good bit. One problem I am having right now in my project is that after implementing the whole video my character keeps sliding a little after I let go of the input key. I assumed that I could fix this with the "ground decay" value to add more drag, but I already put it to the lowest it can be (at 0) and my character still slides a good bit after I let go of the button. Does anyone know how I could bring the player character to a more abrupt stop?
@andylinkOFFICIAL
@andylinkOFFICIAL 3 ай бұрын
awesome!
@loiscarrion2656
@loiscarrion2656 3 ай бұрын
hey Adam, just wondering what you think of the new input system? would you recomend?
@AdamCYounis
@AdamCYounis 3 ай бұрын
Yes, I think it's worth learning. The old input system is fine for simple games but anything with local multiplayer and support for different controllers should use the new input system, or a third party plugin like Rewired.
@piotrradzyminski240
@piotrradzyminski240 3 ай бұрын
Could you do more isometric tutorials? I'm struggling with my isometric RTS game, particulary with VFX and weather
@monkeypwners
@monkeypwners 2 ай бұрын
When I move my character in a side scroller type of game, I slide and accelerate when I'm at 2:25 in the video, if that makes sense
@jesse51495
@jesse51495 Ай бұрын
What editor theme are you using here? Really like the colors.
@AdamCYounis
@AdamCYounis Ай бұрын
This is the Material theme, set to "Ocean"
@sineadhall8351
@sineadhall8351 Ай бұрын
in the part at 9:10 it keeps giving me the Assets\playermovement.cs(25,34): error CS1513: } expected error and i dont know what it is talking about some one please help
@hehexd4787
@hehexd4787 3 ай бұрын
FINALLY
@escapegoat573
@escapegoat573 3 ай бұрын
It would be cool to see a video on reusable code by you. using pseudo code so it's easier to implement in other engines might be a good idea too
@ZombieChicken-X
@ZombieChicken-X 3 ай бұрын
Hi I’m struggling to understand what’s the “correct” or standard approach to dealing with ground checks and player hitboxes when their sprite changes in shape. Another thing I’m wondering about is how do I go about actually building a level? I understand putting down my sprites as gameobjects or using a tilemap but where I’m unsure is properly building the colliders. My current approach is to use a tilemap collider 2D + a composite collider2D but it just feels hacky
@AdamCYounis
@AdamCYounis 3 ай бұрын
Ideally, your character's physics collider / ground check should never change, even if the sprite does. It's much much easier to manage this way and players will not care about the inconsistencies in the sprite silhouette vs physics shape. As for hit boxes and level colliders, I'll cover them in later videos.
@ZombieChicken-X
@ZombieChicken-X 3 ай бұрын
Thank you, looking forward to those vids. Oh one thing I forgot to mention, I'm not going for a pixel art style but rather a hand drawn game. Are there any technical differences I need to consider in relation to physics or level design?
@mewberthildimew9037
@mewberthildimew9037 3 ай бұрын
My only gripe with the way that you've set up the groundCheck collider, is that if your character's feet hit the side of a platform, it will count it as being grounded, which it obviously isn't. The way I usually get around this is by creating a ground detection collider within the player collider that's only slight smaller on the top, right, and left sides, but matches the bottom side, such as that only the bottom of the character will detect ground and not the lower sides. I've yet to run into any issues with this method, but it could definitely make slopes challenging to deal with. Edit: I take it back, I see that a few moments later you set the groundCollider to only consider overlaps rather than simple collisions, which would definitely solve the issue I mentioned, but I'll still keep my comment for posterity in case anyone had similar concerns. That said, I have seen that it's possible to set a Contact Filters, where you can specify a min and max angle to be considered when checking ground collisions in such a way that slopes that exceed the specified angles do no count as being grounded? Any experience with those?
@AdamCYounis
@AdamCYounis 3 ай бұрын
This problem can be solved a couple of ways depending on how complex the terrain and player behaviour need to be. There is always going to be a catch 22. if the ground check is any narrower than the body collider, it'll be possible to be standing right on the edge but not "grounded". If it's wider, "grounded" will be true when touching walls marked as ground. Neither are desirable, but I prefer to solve the latter with additional logic, or a better terrain setup that separates walls and ground more precisely.
@shrooby
@shrooby 3 ай бұрын
A bit outside the scope of this video, but a discussion/debate I've seen over the years is using the built in Unity physics vs making your own physics system for a platformer. Obviously, in the video you use the former, but was still wondering if you have any thoughts on that?
@AdamCYounis
@AdamCYounis 3 ай бұрын
I haven't explored this topic enough to say whether writing a physics system for a precision platformer mechanics from scratch would be more time consuming than modifying Unity's physics. Things like the contact solver are actually not trivial to implement, and would be significant work, unless the game doesn't need those kinds of features.
@drinya_risovach
@drinya_risovach 3 ай бұрын
Man, I want to make my own game, but I don't know how to begin learning coding. Do you have some advice? How did you begin learning coding?
@DigiLena
@DigiLena 3 ай бұрын
I know you debated godot on your live stream, but still would love these to be also for godot.
@Chickenfryguy
@Chickenfryguy 18 күн бұрын
Guy's can someone help me, I was trying to follow along but then an error popped up even though I did everything the guy said to do (The error popped up at the part where you start coding)
@Borgor_Eater
@Borgor_Eater 28 күн бұрын
when i jump it doesn't jump the full height (it would do a tiny hop) unless i hold the jump button is there a way to fix this?
@AdamCYounis
@AdamCYounis 23 күн бұрын
In the video I get around this by only applying friction with a surface if your velocity.y is
@RakeBye22
@RakeBye22 21 күн бұрын
Have you resolved the problem? I'm experiencing the same issue.
@BeerHuntor
@BeerHuntor 3 ай бұрын
Do you delete your youtube vods older than a month? wanted to go back and watch the LD godot streams and only lives on there are no longer than a month old :(
@AdamCYounis
@AdamCYounis 3 ай бұрын
I wasn't streaming on KZbin before a month ago! Twitch has always been my primary platform.
@TomDytorn
@TomDytorn 15 күн бұрын
i can't get Vector2 direction to work
@o2arya104
@o2arya104 3 ай бұрын
Bro I know u have made video on character size and canvas size but we want to know the exact size of ur game characters and ur canvas size, map size, tileset size, etc
@GE2_Pink
@GE2_Pink Ай бұрын
why doesn't unity recognise "direction" when coding the movement speed?
@Sharky0204
@Sharky0204 23 күн бұрын
nothing that says "body" shows up here 4:29
@phoenixplayzz2676
@phoenixplayzz2676 Ай бұрын
Crouch tutorial please
@tayfuntuna
@tayfuntuna 12 күн бұрын
I had to watch at 0.75x
@arcaneminded
@arcaneminded 3 ай бұрын
weren't you moving away from Unity?
@AdamCYounis
@AdamCYounis 3 ай бұрын
It's the engine I have the most experience in, (I'm still making my passion project in it) and the place I can share the most value as a content creator, given that the audience is still greater for Unity than any other engine. The decision was not made lightly, of course. I am still excited to explore other engines in my free time, particularly Godot which I enjoyed experimenting with last year. Maybe when I have more experience there I can create tutorials for it, too.
@wordsandletter
@wordsandletter 3 ай бұрын
I don't understand anything.
@ShinoSarna
@ShinoSarna 3 ай бұрын
Shame that this series won't help me, since the 'runtime fee' stunt made me lose any possible interest in Unity.
Code Class - Build your own State Machines!
36:42
AdamCYounis
Рет қаралды 33 М.
How I made an Excellent Platformer
8:25
GoldenEvolution
Рет қаралды 251 М.
ONE MORE SUBSCRIBER FOR 6 MILLION!
00:38
Horror Skunx
Рет қаралды 15 МЛН
어른의 힘으로만 할 수 있는 버블티 마시는법
00:15
진영민yeongmin
Рет қаралды 12 МЛН
Заметили?
00:11
Double Bubble
Рет қаралды 3 МЛН
The Trick I Used to Make Combat Fun! | Devlog
8:12
Game Endeavor
Рет қаралды 1,6 МЛН
Level editing made easy with Automapping
34:36
AdamCYounis
Рет қаралды 219 М.
16x16 Character Sprites Drawn In Real Time - Pixel Art Tutorial And Process
12:22
Secrets to a Great Platformer Character with Unity
3:11
Dawnosaur
Рет қаралды 53 М.
5 tips for better platformer controls
5:22
The Shaggy Dev
Рет қаралды 179 М.
The Ultimate Pixel Art Tutorial
14:15
Saultoons
Рет қаралды 1,4 МЛН
Improve Your Platformer with Forces | Examples in Unity
7:01
Dawnosaur
Рет қаралды 164 М.
An Aseprite Crash Course In 30 Minutes
31:47
AdamCYounis
Рет қаралды 1 МЛН
Improve your Platformer’s Jump (and Wall Jump) | Unity
8:12
ПК с Авито за 3000р
0:58
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 1,7 МЛН
как спасти усилитель?
0:35
KS Customs
Рет қаралды 525 М.
Power up all cell phones.
0:17
JL FUNNY SHORTS
Рет қаралды 50 МЛН
МОЖНО ЛИ заряжать AirPods в чехле 🧐😱🧐 #airpods #applewatch #dyson
0:22
Apple_calls РЕПЛИКА №1 В РФ
Рет қаралды 23 М.