Code Class - 2D Player Movement in Unity

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ก.ค. 2024
  • (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!
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 82

  • @zacccore
    @zacccore 4 หลายเดือนก่อน +9

    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!

  • @marissamorris778
    @marissamorris778 4 หลายเดือนก่อน +8

    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. :)

  • @Notreal76
    @Notreal76 4 หลายเดือนก่อน +10

    You have a gift for teaching. It comes so easy to listen and follow.

  • @Vesrayech
    @Vesrayech 4 หลายเดือนก่อน +12

    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  4 หลายเดือนก่อน +4

      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.

  • @jtacua7822
    @jtacua7822 4 หลายเดือนก่อน +3

    YEEEEEEEAH I'VE BEEN WAITING THIS KIND OF TUTORIALS FROM YOU! THANKS!

  • @franskeeh
    @franskeeh 4 หลายเดือนก่อน +2

    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 4 หลายเดือนก่อน +2

    Great video! I love your dev journals, but I really truly enjoy your instructional videos for Unity and/or pixel art. Thanks!

  • @CharlesA.
    @CharlesA. 4 หลายเดือนก่อน +1

    I was looking forward this one. Thank you so much Adam. We really appreciate you bro !

  • @Ilgar1
    @Ilgar1 4 หลายเดือนก่อน +2

    I literally was searching for this and I saw your upload. Bless you

  • @Ebenchadnezzar
    @Ebenchadnezzar 4 หลายเดือนก่อน +1

    This was soo helpful, please continue this series!

  • @jeremieboulay4805
    @jeremieboulay4805 4 หลายเดือนก่อน +1

    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!

  • @louiscorbett4834
    @louiscorbett4834 4 หลายเดือนก่อน

    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 4 หลายเดือนก่อน

    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!

  • @JimmyCeeTV
    @JimmyCeeTV 3 หลายเดือนก่อน

    Just the info I was looking for, and very well explained. More like this please 🙏

  • @NeatGames
    @NeatGames 4 หลายเดือนก่อน +3

    The detailed explanations are awesome :D

  • @tombandiera9083
    @tombandiera9083 3 หลายเดือนก่อน +1

    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 :)

  • @globes179
    @globes179 4 หลายเดือนก่อน +2

    Nice, would love to hear more in the later vids

  • @stefans3780
    @stefans3780 4 หลายเดือนก่อน +3

    these are incredibly useful and understandable, you're really good at explaining things
    Thanks!

  • @ELF_Productions
    @ELF_Productions 4 หลายเดือนก่อน +1

    I love to see the explanations on the coded version of friction and acceleration. Awesome tutorial and well explained

  • @sitrusjo
    @sitrusjo 4 หลายเดือนก่อน

    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

  • @mehmetberkayyalcn9009
    @mehmetberkayyalcn9009 2 หลายเดือนก่อน

    Thank you . Your video is better than most of the others and it helped me.

  • @teddysundin2992
    @teddysundin2992 2 หลายเดือนก่อน

    This is awesome! Exactly what i was looking for!

  • @truongthan6593
    @truongthan6593 4 หลายเดือนก่อน +1

    Yesss, i need this so much! Thank youu

  • @esvanquiroz1996
    @esvanquiroz1996 3 หลายเดือนก่อน +1

    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.

  • @solodevelopmentstudio7645
    @solodevelopmentstudio7645 4 หลายเดือนก่อน +1

    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 3 หลายเดือนก่อน +1

    Just discovered this series and it’s exactly what I needed. Great content from what I’ve watched so far!

  • @simonhughes1324
    @simonhughes1324 4 หลายเดือนก่อน +1

    Thank you Adam.

  • @iam.thomas
    @iam.thomas 3 หลายเดือนก่อน +1

    This is gold, thanks!

  • @CoderFromTurkey
    @CoderFromTurkey 4 หลายเดือนก่อน +2

    Thanks for the video!

  • @ty-xq7bl
    @ty-xq7bl 4 หลายเดือนก่อน

    Best guide for 2d

  • @Kdoe0_0
    @Kdoe0_0 3 หลายเดือนก่อน +1

    my gosh thank you!

  • @seanrendall5495
    @seanrendall5495 3 หลายเดือนก่อน +2

    Gotta say, this is a lot better than the code ChatGPT wrote for me. Ai coding has a long way to go, still.

  • @alejmc
    @alejmc 4 หลายเดือนก่อน

    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…

  • @hehexd4787
    @hehexd4787 4 หลายเดือนก่อน +1

    FINALLY

  • @andylinkOFFICIAL
    @andylinkOFFICIAL 4 หลายเดือนก่อน

    awesome!

  • @mewberthildimew9037
    @mewberthildimew9037 4 หลายเดือนก่อน

    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  4 หลายเดือนก่อน +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.

  • @escapegoat573
    @escapegoat573 4 หลายเดือนก่อน

    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

  • @piotrradzyminski240
    @piotrradzyminski240 4 หลายเดือนก่อน

    Could you do more isometric tutorials? I'm struggling with my isometric RTS game, particulary with VFX and weather

  • @DigiLena
    @DigiLena 4 หลายเดือนก่อน

    I know you debated godot on your live stream, but still would love these to be also for godot.

  • @loiscarrion2656
    @loiscarrion2656 4 หลายเดือนก่อน

    hey Adam, just wondering what you think of the new input system? would you recomend?

    • @AdamCYounis
      @AdamCYounis  4 หลายเดือนก่อน +1

      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.

  • @Anjecam
    @Anjecam 27 วันที่ผ่านมา +1

    Is it me or the jump heigh is lower if player is not moving?

  • @Jecyn14
    @Jecyn14 2 หลายเดือนก่อน

    What editor theme are you using here? Really like the colors.

    • @AdamCYounis
      @AdamCYounis  2 หลายเดือนก่อน +1

      This is the Material theme, set to "Ocean"

  • @Borgor_Eater
    @Borgor_Eater 24 วันที่ผ่านมา

    sry for so many questions but was wandering when i take damage i get dealt double the damage in some spots cuz of the 2 colliders is there a way no to?

  • @TK-dz2vu
    @TK-dz2vu หลายเดือนก่อน

    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?

  • @shrooby
    @shrooby 4 หลายเดือนก่อน

    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  4 หลายเดือนก่อน +1

      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.

  • @AndresCampos-tx1lr
    @AndresCampos-tx1lr 27 วันที่ผ่านมา

    Why do you multiply the groundDecay in the y Axis? This in the ApplyFriction method.

  • @ZombieChicken-X
    @ZombieChicken-X 4 หลายเดือนก่อน

    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  4 หลายเดือนก่อน +2

      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 4 หลายเดือนก่อน

      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?

  • @monkeypwners
    @monkeypwners 3 หลายเดือนก่อน

    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

  • @TomDytorn
    @TomDytorn หลายเดือนก่อน

    i can't get Vector2 direction to work

  • @sineadhall8351
    @sineadhall8351 2 หลายเดือนก่อน

    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

  • @drinya_risovach
    @drinya_risovach 4 หลายเดือนก่อน

    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?

  • @o2arya104
    @o2arya104 4 หลายเดือนก่อน

    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

  • @BeerHuntor
    @BeerHuntor 4 หลายเดือนก่อน

    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  4 หลายเดือนก่อน

      I wasn't streaming on TH-cam before a month ago! Twitch has always been my primary platform.

  • @phoenixplayzz2676
    @phoenixplayzz2676 2 หลายเดือนก่อน

    Crouch tutorial please

  • @Elias.Mamoud
    @Elias.Mamoud 7 วันที่ผ่านมา

    i keep getting a syntax error on the vector 2 part, idk why someone help please

  • @GE2_Pink
    @GE2_Pink 2 หลายเดือนก่อน

    why doesn't unity recognise "direction" when coding the movement speed?

  • @Chickenfryguy
    @Chickenfryguy หลายเดือนก่อน

    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)

  • @Sharky0204
    @Sharky0204 หลายเดือนก่อน

    nothing that says "body" shows up here 4:29

  • @Borgor_Eater
    @Borgor_Eater หลายเดือนก่อน

    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  หลายเดือนก่อน +1

      In the video I get around this by only applying friction with a surface if your velocity.y is

    • @RakeBye22
      @RakeBye22 หลายเดือนก่อน

      Have you resolved the problem? I'm experiencing the same issue.

    • @Borgor_Eater
      @Borgor_Eater 25 วันที่ผ่านมา

      @@RakeBye22 i have i forgot to remove the comment but it was 2 days after i commented and i forgot how i fixed it im pretty sure i typed something in wrong so its good now again sorry

    • @Borgor_Eater
      @Borgor_Eater 25 วันที่ผ่านมา

      @@AdamCYounis sorry for this its not really a problem but i was wandering is there a way to get rid of the ground slide. whenever i click the button for a second it and stop either immediately or after alittle bit it slides a set distance i tried adjusting the gound decay, max X speed, but it doesnt seem to matter

    • @AdamCYounis
      @AdamCYounis  25 วันที่ผ่านมา +1

      @@Borgor_Eater if you don't want to use any friction, you can just set the velocity.x to 0 if the character is grounded and there are no horizontal keys being pressed.

  • @shrom6753
    @shrom6753 5 วันที่ผ่านมา

    21:13 how am I supposed to follow this

  • @kaneros1997
    @kaneros1997 18 วันที่ผ่านมา

    my gravity is lower or moves slower down then yours with linear drag on 10 i float down like in honey idk why my linear drag is 0

  • @tayfuntuna
    @tayfuntuna หลายเดือนก่อน

    I had to watch at 0.75x

  • @Kenon-
    @Kenon- 5 วันที่ผ่านมา

    at 7:06 he changes the code without telling anything, i got tricked by this lol

  • @wordsandletter
    @wordsandletter 4 หลายเดือนก่อน

    I don't understand anything.

  • @arcaneminded
    @arcaneminded 4 หลายเดือนก่อน

    weren't you moving away from Unity?

    • @AdamCYounis
      @AdamCYounis  4 หลายเดือนก่อน

      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.

  • @ShinoSarna
    @ShinoSarna 4 หลายเดือนก่อน

    Shame that this series won't help me, since the 'runtime fee' stunt made me lose any possible interest in Unity.