4 Ways to Code 2D Player Movement in Unity (You SHOULD know these!)

Поділитися
Вставка
  • Опубліковано 7 лют 2025

КОМЕНТАРІ • 233

  • @TheZamirOrion
    @TheZamirOrion 4 роки тому +378

    Wow, finally someone who takes the time to explain how things works instead of proposing ready made solutions that nobody understands. Thank you so much.

    • @meganixi5282
      @meganixi5282 4 роки тому +19

      i've seen a lot of people just saying "copypaste the script in the description", people cant learn by copypasting scripts!

    • @r.i.petika829
      @r.i.petika829 4 роки тому +1

      @@meganixi5282 true

    • @beggi4393
      @beggi4393 4 роки тому

      @R.I.P Etika true

    • @reaperplayz8806
      @reaperplayz8806 4 роки тому

      Puffer Plays true

    • @meganixi5282
      @meganixi5282 4 роки тому

      @@reaperplayz8806 true

  • @xp_diablo
    @xp_diablo 4 роки тому +128

    I've watched a lot of tutorials and stuff on movement in 2D games, and I've seen all the different ways they do it, but never explained. Came across this video, and now it's all clear to me. Thanks :)

    • @LostRelicGames
      @LostRelicGames  4 роки тому +9

      Hey thanks for taking the time to write that, I really appreciate it. I'm glad I was able to help.

    • @justgames4037
      @justgames4037 4 роки тому +1

      @@LostRelicGames yes brother it helping us. pls dont stop doing tutorials .

    • @B8Code
      @B8Code 4 роки тому

      ua-cam.com/video/YzCF3zbfUE0/v-deo.html

  • @maycontainnuts3127
    @maycontainnuts3127 2 роки тому +1

    best tutorial for basic unity ive ever seen. i dont know how people can learn just by copying someone else's code, actually having the process in front of me and explained is absolutely brilliant.

  • @Kudoshi
    @Kudoshi 3 роки тому +42

    4 ways of movement:
    PHYSICS BASED
    1. Velocity
    2. Addforce (Type: force - slowly moves up the force; impulse - no build up instant force)
    NON-PHYSICS BASED
    3. Position
    4. Translate

  • @youneskasdi
    @youneskasdi 4 роки тому +25

    Gave me great understanding of how to actually make my own movement script unlike the rest of those youtube tutorials where they just use an already made script, thank you so much

    • @LostRelicGames
      @LostRelicGames  4 роки тому +4

      My pleasure blood moon, I'm truly glad to hear it. All the best in the exciting road ahead!

  • @ezekieldominiquintal7556
    @ezekieldominiquintal7556 3 роки тому +5

    wow this is seriously underrated. you deserve more support.
    simple things like this allows beginners to develop more creative ideas because we get to understand the parts of the script itself whereas others only provides results of using a certain script. your way makes us be more confident in experimenting on the engine on our own.

  • @nashonightmare
    @nashonightmare Рік тому

    Please give us tutorials like this again. They are really amazing and not boring to watch. You are clearly explaining the things and reason behind them. Thank you very much. This channel is underrated.

  • @maliksaraanasim5404
    @maliksaraanasim5404 3 роки тому +3

    I wanna express my sincere gratitude to you. I have been so many tutorials and this is just the thing that I wanted. "The difference between different movements" . All I ever got was "Confusion" UNTIL NOW

  • @seballo2707
    @seballo2707 4 роки тому +4

    Dude your videos are the best thing I've found on youtube about Unity.

  • @ogibogi2004
    @ogibogi2004 4 роки тому +3

    I don't know why he has so little subscribers. He is probably the best teacher i found so far that actually helped me explaining every little detail. Thank you man. You're the best

    • @B8Code
      @B8Code 4 роки тому

      ua-cam.com/video/YzCF3zbfUE0/v-deo.html

  • @goodgamershow6505
    @goodgamershow6505 4 роки тому +3

    Thank you so much for clear explanation! I was using unity for about a week and just copy pasted somebody's movement script without understanding what it does, but now i can write my own movement script and it's all thanks for you

  • @axolotlaxel
    @axolotlaxel 4 роки тому +3

    This is great, I'm a software engineer trying to become a game developer and despite being a software engineer I'm not great at coding, so this is really helpful, I have always wanted to develop games and I'm currently working on my first, thanks for the help!

  • @codinginflow
    @codinginflow 3 роки тому +17

    Terrific explanation, thank you

  • @JohnnyThousand605
    @JohnnyThousand605 3 роки тому +3

    One thing I would add; if you manipulate an object via its transform, you kind of break the physics interactions. So objects that should 'bounce' off each other will potentially pass through each other. If your player character runs against a dead end wall it will jitter rather than if you use velocity / force where it will simply stop moving (your run animation might keep going but that's a whole different thing ;-) )

  • @JustN4n0
    @JustN4n0 4 роки тому +5

    Thank you!
    All of the tutorials I watched never explained how those work, and never understood until now, great vid! :)

  • @mateotellez3639
    @mateotellez3639 3 роки тому +1

    Amazing. I've seen so many tutorials of movement but its center on a specific idea and this video explains every type of movement so you can choose which one to use depending on YOUR idea and not on the videos idea. Thank You so much

  • @alexcernescu5868
    @alexcernescu5868 4 роки тому

    I didn't knew why FixedUpdate , but not Update... You just make it clear not just for me, but for the 64k viewers too. Keep it up!

  • @muhamamdjamali1114
    @muhamamdjamali1114 4 роки тому +1

    Awesome tutorial better than anyone i found on youtube described breifly and to the point keep it up man love u

  • @Kyjor_
    @Kyjor_ 5 років тому +11

    This is so practical! Helped me figure about an issue with my 2D character!

  • @Alex-re3qm
    @Alex-re3qm 3 роки тому

    only video I found that actually helped me understand what to do and what the code does

  • @gareebdevelopers3079
    @gareebdevelopers3079 4 роки тому +1

    Thank You Sir For Making This Video , My every doubt regarding movement, now has been cleared, u explained everything in details ofcourse with live examples, i really like the way u teach, Keep up the good work.

  • @dandelion44444
    @dandelion44444 4 роки тому

    I wanted to start programming as a digital artist but could’t find any good tutorials but then I found your channel and it have helped me a lot! Thank you for great content x3

    • @B8Code
      @B8Code 4 роки тому

      ua-cam.com/video/YzCF3zbfUE0/v-deo.html

  • @kidscanvas4141
    @kidscanvas4141 2 роки тому +1

    Best video for beginners.but please it's a request to place your all videos on unity in a playlist

  • @keventy6114
    @keventy6114 4 роки тому +29

    .AddForce: Spaceship game, here I come!

  • @overlorde7526
    @overlorde7526 4 роки тому +1

    There are just not enough tutorials on 2d movement, thank you so much

  • @shamangrayson8143
    @shamangrayson8143 Рік тому

    Thank you so much for this video. Really helping me understand some of the fundamentals better!

  • @pauljoneseyboy9615
    @pauljoneseyboy9615 4 роки тому +1

    I’ve been struggling to learn this stuff, with this video it just *clicked* thanks so much!

  • @LostRelicGames
    @LostRelicGames  4 роки тому +17

    ​►Unity Asset I made to help beginners make platformers - ​u3d.as/2eYe​
    ► Wishlist my game - store.steampowered.com/app/1081830/Blood_And_Mead/

    • @MemeScope
      @MemeScope 4 роки тому +7

      that brings up the assetstore only

    • @kevinmantao1357
      @kevinmantao1357 3 роки тому

      The link is broken.

    • @sophiehealey4783
      @sophiehealey4783 3 роки тому +1

      Hi, I know you probably won't see this but I just thought I might try. I'm having trouble with the code, (this is the first example you showed I'm talking about) when I add the "else {buttonPressed = null;}" the code stops working and no error comes up in the console or anything. I added a Debug.Log thing to test if the code to move the player to the right worked, and it magically fixed the problem. So then I thought I'd put in the part of the code to make the player move to the left, and then the code stopped working again. I tested some more, and when I tok the buttonPressed = null; away completely from the code it started working but the player won't stop moving, and when I put the buttonPressed = null; back the code stops working again. I don't know what's wrong. If it isn't too much trouble could you maybe help me or point me in the right direction? No worries if you can't of course.
      edit: I've changed the script and now if I spam the button it might move a little

    • @XionaZiba
      @XionaZiba 3 роки тому

      man, i cant see the speed in the component.

  • @오진석-z6v
    @오진석-z6v 3 роки тому

    This is by far the best tutorial on moving 2d characters. Thank you so much!

  • @muhammedalshameri801
    @muhammedalshameri801 4 роки тому

    Finally someone explain what every function do. You were a big help, thanks man.

  • @LuisCanary
    @LuisCanary 4 роки тому +3

    Very good video, I learned a lot, thanks :D

  • @someoneyoudontknow2704
    @someoneyoudontknow2704 4 роки тому +1

    Defenitly subscribed! Your explanations helped a lot! Keep it going like that, its the best way for beginners to understand how this language works! thank you very much!

  • @rlopera
    @rlopera 2 роки тому

    Thanks so much. Brilliant start point to start learning.

  • @Studi0usKidd0
    @Studi0usKidd0 4 роки тому

    A few of your points such as using FixedUpdate and not to use transform position with rigid bodies were something I had to figure out by myself. Wish I had come across your video earlier. Great tutorial nonetheless

    • @LostRelicGames
      @LostRelicGames  4 роки тому +1

      Thanks Hari, glad to hear you are making progress! Wishing you the best on the path ahead

  • @saifgames2468
    @saifgames2468 5 років тому +13

    Awesome bro i like your tuts, and i was wondering if you can make tuts serie about making complete 2D game from scratch for beginners and inclouds many features like kicking, shooting and all this cool stuff.

    • @LostRelicGames
      @LostRelicGames  5 років тому +8

      Thanks for the comment! I'd absolutely love to, I'm a actually just waiting for unity to officially release the new input system, as it will have a critic effect on any big video series make

    • @aarondelgado3421
      @aarondelgado3421 5 років тому

      I am excited for the new input system. Once you make a video on the new input system that is officially out of preview, please cover how mobile inputs work under this system.

  • @TheSerphmx
    @TheSerphmx 5 років тому

    Awesome! I recently found your channel and it is helping me to polish my knowledge, keep it up and thank you for sharing!

    • @LostRelicGames
      @LostRelicGames  5 років тому

      Nice one dude, you're a good man. Swing by the discord if you ever need to chat

  • @jaskarnjass8548
    @jaskarnjass8548 5 років тому +1

    Awesome tutorial🤩🤩 .Please make a full course of your tutorials on 2d games. Keep the good work

  • @andresabadiadeveloper1489
    @andresabadiadeveloper1489 3 роки тому

    men, this is gold, thanks for this!

  • @sethfleshman4137
    @sethfleshman4137 4 роки тому +1

    This is literally epic, thank you so much

  • @mantawhitest1895
    @mantawhitest1895 2 роки тому

    "You SHOULD know these!"
    Me: *Laughs in no experience*

  • @soggybons
    @soggybons 5 років тому

    Cool video! for reference, adding to transform.position and using transform.translate are doing the exact same thing. using space.self is the exact same as adding to transform.localPosition and using space.world is the same as adding to transform.position

  • @Cubic_Gaming
    @Cubic_Gaming 2 роки тому

    8:00
    could be used for moving through a river which is flowing into the opposite direction

  • @shreyas908
    @shreyas908 4 роки тому

    subscribed!!! no time wasted i thank you !!! your are life saver

  • @JC-jz6rx
    @JC-jz6rx 5 років тому +6

    this is great stuff, came from Reddit

  • @phantomclan3156
    @phantomclan3156 4 роки тому +1

    Great Work! You just got a new subbed

  • @reblfist8849
    @reblfist8849 5 років тому

    Amazing video liked and subscribed thank you you are a very good teacher!

  • @fakefake6770
    @fakefake6770 2 роки тому +1

    Cool video thank you so much!!!

  • @JohnDoe-oh7gf
    @JohnDoe-oh7gf 10 місяців тому

    I'm late to the party but enjoyed it.

  • @hajee_talsy
    @hajee_talsy 3 роки тому

    Thank you so much, I managed to understand how to finally make my square move

  • @sakuraggg1533
    @sakuraggg1533 3 роки тому

    helped me lot about coding

  • @auscan7739
    @auscan7739 3 роки тому

    thanks! helped me a lot with my game

  • @THEspindoctor84
    @THEspindoctor84 4 роки тому

    this is a great tutorial, and well explained!

  • @8blitzgamer179
    @8blitzgamer179 4 роки тому

    thanks for adding the code for it

  • @abhishekdhiman6845
    @abhishekdhiman6845 4 роки тому

    Really Appreciate Bro Thank a lot for this Really good Explain all techniques and their working❤✨✨

  • @peacesafe3087
    @peacesafe3087 4 роки тому

    I'M IN 5:00 AND I THINK YOU ARE A "LEGEND"

  • @casachezdoom2588
    @casachezdoom2588 3 роки тому +1

    15:25 old school kung fu movie dubbing vibes right there!
    "You have insulted my Unity Sifu, prepare to die!" XD

  • @stoicalsilence
    @stoicalsilence 4 роки тому

    Thank you for the explanations.

  • @Gamingawesomeness121
    @Gamingawesomeness121 4 роки тому

    thank you dude this was a lot of help!

  • @azueta9
    @azueta9 2 роки тому

    Awesome video thank you so much!

  • @JakeSimmer
    @JakeSimmer Рік тому

    Ow wow, even if you don't believe, you may have heard, the Lord works in misterious ways, or something along those lines. Now I know, this is youtube and there's an algorythm but this is what happened. I saw an inspiring vid about why quitting alcohol is good. In that was a piece of an interview on Howard Stern with Ben Affleck about his journey with quitting alcohol, so I wanted to find the whole interview. I opened a new tab, but because I have been looking into 2d programming as well, this vid popped up. Finally I would say, because the beginning is very very steep... AND as a bonus, 4 more vids on the side about 2d movement and examples. Whooo!! Anyway, still gonna watch that intervieuw because I'm actually very tired of that contatnt battle with the bottle. But I want to happily say, it came all together on 8-7-2023 All the best to you and your jounrey in live. Please keep following your heart and dare to ask for help and support by the people around you. Later alligator!! ;-) Jake

  • @skippynik6003
    @skippynik6003 4 роки тому

    This is the best movement related tutorial Ive ever seen on UA-cam . I have a small doubt, why physics related stuffs are kept under FixedUpdate() instead update() ?

    • @sapazu
      @sapazu 4 роки тому +1

      FixedUpdate() is synced to Unity's physics engine

    • @skippynik6003
      @skippynik6003 4 роки тому +1

      @@sapazu Thanks man .

  • @danielbenyair300
    @danielbenyair300 2 роки тому

    writing "public Rigidbody2D RB;" is enough because then you can drag the component to the sxript to attach them

    • @Chubzdoomer
      @Chubzdoomer 2 роки тому

      Then you're exposing the RB field to every other script, meaning they can potentially modify/alter it. You shouldn't go around making everything public unless there's a good reason for it. If all you're wanting is drag-and-drop functionality in the Inspector, use the SerializeField attribute instead and keep the field either private or protected!

  • @kirillkir6268
    @kirillkir6268 4 роки тому +1

    Great video, thx!

  • @legendguitargamer
    @legendguitargamer 4 роки тому

    Helped a lot bro! Thanks

  • @Perfectbeing1045
    @Perfectbeing1045 3 роки тому

    I feel that you will be the next brackeys.

  • @MEGA_TREE
    @MEGA_TREE 2 роки тому

    So helpful

  • @blockishgaming8459
    @blockishgaming8459 5 років тому

    thanks u deserve more attention

  • @rezazolgharnein7609
    @rezazolgharnein7609 3 роки тому

    Hello, please make a video about the player pulling and pushing the block

  • @Repanon00
    @Repanon00 5 років тому

    Great info! Very helpful!

  • @georgeak4454
    @georgeak4454 3 роки тому

    Amazing man

  • @arnolditdang3791
    @arnolditdang3791 4 роки тому

    i have understand physics thank youuuu!!!!!!!!

  • @MyPianoRoom
    @MyPianoRoom 5 років тому +1

    Thanks for upload this tutorial ^^

  • @briacovidiu4845
    @briacovidiu4845 2 роки тому

    finally someone that tells us why tf we do what we do

  • @tungstenelephant9849
    @tungstenelephant9849 4 роки тому

    Thank you so much for this!

  • @khangteh
    @khangteh 4 роки тому

    Awesome! Great Tutorial!

  • @emmanuelperez48
    @emmanuelperez48 4 роки тому

    Excelentemente explicado, muchas gracias por la información, suscrito

  • @AirskiiMusic
    @AirskiiMusic 4 роки тому +1

    Hey you missed one that i really want to know! You know like Oddworld abe's oddysee where the character appears to walk smoothyl but i think there's a grid under the hood because you cannot position yourself in certain spots, there's a set number of places you can stand. This was a very good video though and useful for learning physics movement thank you :)

  • @val_ience4993
    @val_ience4993 2 роки тому

    this is the only video where they explain stuff

  • @foreducation408
    @foreducation408 2 роки тому

    awesome video

  • @3604marine
    @3604marine 3 роки тому

    I wonder who the hell dislikes this guys videos!!

  • @wolkenfarmer
    @wolkenfarmer 4 роки тому +3

    I am really new to Unity, C# and a bit programming too, so thank you for this really helpful tutorial! I like how you really explain this stuff on a coding level for beginners instead of just dragging and dropping working stuff.
    However, I wonder why your Visual Studio seems to give you always the best next suitable words while writing code and mine not (or at least less). Therefore I cannot really explore all the different Methods given, but have to find them out via internet one by one. I downloaded unity and VS just recently - is there any setting I just have activate or what could be the reason for this?

    • @LostRelicGames
      @LostRelicGames  4 роки тому

      Hey mate! Make sure VS is linked to unity inside the unity preferences

    • @wolkenfarmer
      @wolkenfarmer 4 роки тому +1

      @@LostRelicGames Helped! Thank you. :)
      However.. it confuses me, that it wasn't selected automatically, because I installed VS through Unity. xD

  • @cheryllockhart6195
    @cheryllockhart6195 2 роки тому

    How did you first start off? How did you attach the rigid body? How did you do the box collider thing? Everyone assumes you already know this.... :(

  • @CrimsonEverFrost
    @CrimsonEverFrost 4 роки тому +1

    i have a problem where it says Assets\PlayerController.cs(33,33): error CS1002: ; expected
    although when i put a ; to
    ButtonPressed = null
    Then 7 more errors pop up

  • @MarxyBasement
    @MarxyBasement 5 років тому +1

    HELPFUL

  • @pfp4ever
    @pfp4ever 2 роки тому

    12:40 replace *5 with a variable called something like speed

  • @zekiozdemir420
    @zekiozdemir420 4 роки тому

    thank you

  • @goodgamershow6505
    @goodgamershow6505 4 роки тому

    If anybody faces a problem of character not moving when using AddForce, increase the moveSpeed value of the script

  • @alvarosanchez8066
    @alvarosanchez8066 4 роки тому

    Just Thank You.

  • @Fictionart977
    @Fictionart977 3 роки тому

    I have subscribed!!!

  • @sophiehealey4783
    @sophiehealey4783 3 роки тому +1

    'sWhen I pressed play the player just floats down really slowly and when I press D or A (I have this instead of the arrow keys) the player doesn't move. I don't know what's wrong, is there anyone who could help? btw I am at 3:11 in the video
    edit: I figured out why the character was falling so slowly (it's the gravity thing under rigidbody2D) but I still don't know how to fix the player movement

  • @hercules5546
    @hercules5546 4 роки тому

    awesome, ty so much !!

  • @omg8264
    @omg8264 4 роки тому

    My favourite method 12:56

  • @elisaarasa1576
    @elisaarasa1576 4 роки тому

    This video is a gem thank you so much 😊

  • @nihatheybtov5956
    @nihatheybtov5956 4 роки тому +1

    İ used velocity code but my character just jump one times why? Probably i didn't write code correctly

  • @necrow4155
    @necrow4155 Рік тому

    You confirmed my suspicion of fixedUpdate vs Update. I only started a few weeks ago hence me green behind my ears.

  • @kolvis1
    @kolvis1 3 роки тому +1

    2:21, i have a problema, i tried to attepmt "roll a ball" tutorial from unity
    But, when i type "Vector2", the color remain the same, just like a random text without a meaning or a role
    Can anyone tell me what.s wrong?

    • @nilsleonhardt
      @nilsleonhardt 3 роки тому

      What do you mean with color remain the same?

  • @echratus
    @echratus 4 роки тому

    I came from a unity basics video and decided I wanted to start my own project from here this video. just curious will you ever have like a long tutorial of Unity 2d for beginners with kicks other attacks etc? Also do you have any tips for me for my learning process. Thank you very much

  • @ElboxD
    @ElboxD 3 роки тому

    Great video! One question. Time.deltaTime is only used in the Update and not in FixedUpdate, right?

    • @Chubzdoomer
      @Chubzdoomer 2 роки тому

      If Time.deltaTime is used inside FixedUpdate, it automatically returns Time.fixedDeltaTime. In other words, you can safely use Time.deltaTime everywhere.
      Source: docs.unity3d.com/ScriptReference/Time-deltaTime.html
      (See the second line on that page.)

  • @athvgaming4959
    @athvgaming4959 4 роки тому

    thanks a lot

  • @CreepyUncleIdjit
    @CreepyUncleIdjit 5 років тому +1

    Great tutorial as always! Forgive me if you've already covered this, but how would you apply Unity's new Input System to this? I'm having a devil of a time figuring it out.

    • @LostRelicGames
      @LostRelicGames  5 років тому

      Hey dude, glad you liked it! I'm yet to start fully playing with the new input system. waiting for it to be officially part of the unity release. I have a feeling every single tutorial and unity resources on the internet will break as a result of their changes! :)

    • @CreepyUncleIdjit
      @CreepyUncleIdjit 5 років тому

      @@LostRelicGames Yeah, it certainly seems that way. Trying to reference the input system in the code isn't as intuitive as the methods you use for simple movement. Thank you for all your wonderful tutorials, and I've already wishlisted your upcoming game.