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

  Рет қаралды 171,907

Lost Relic Games

Lost Relic Games

Күн бұрын

► Easily Make Platfomers in Unity - u3d.as/2eYe​
​​► Easily Make Car Games in Unity - u3d.as/1HFX
► Wishlist my game - store.steampowered.com/app/10...
➤ Join the community - / discord
➤ Support on Patreon - / lostrelicgames
How I saved my game from Disaster (Devlog)
➤ • Nintendo Saved my Drea...
Subscribe here for more cool tutes
➤bit.ly/2MpZ1ao
Sample Project files:
➤drive.google.com/file/d/1fC9N...
Video desc:
In this unity game dev tutorial we look at several different approaches to coding player movement and walk (in c#), an important aspect of any 2D player controller script.
#gamedev #unity

Пікірлер: 238
@TheZamirOrion
@TheZamirOrion 4 жыл бұрын
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 жыл бұрын
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 жыл бұрын
@@meganixi5282 true
@beggi4393
@beggi4393 4 жыл бұрын
@R.I.P Etika true
@reaperplayz8806
@reaperplayz8806 4 жыл бұрын
Puffer Plays true
@meganixi5282
@meganixi5282 4 жыл бұрын
@@reaperplayz8806 true
@Kudoshi
@Kudoshi 2 жыл бұрын
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
@xp_diablo
@xp_diablo 4 жыл бұрын
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 жыл бұрын
Hey thanks for taking the time to write that, I really appreciate it. I'm glad I was able to help.
@justgames4037
@justgames4037 4 жыл бұрын
@@LostRelicGames yes brother it helping us. pls dont stop doing tutorials .
@B8Code
@B8Code 3 жыл бұрын
kzbin.info/www/bejne/j6umd2awl8uIe5I
@nashonightmare
@nashonightmare 4 ай бұрын
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.
@youneskasdi
@youneskasdi 4 жыл бұрын
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 жыл бұрын
My pleasure blood moon, I'm truly glad to hear it. All the best in the exciting road ahead!
@maycontainnuts3127
@maycontainnuts3127 Жыл бұрын
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.
@ezekieldominiquintal7556
@ezekieldominiquintal7556 2 жыл бұрын
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.
@mateotellez3639
@mateotellez3639 2 жыл бұрын
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
@keventy6114
@keventy6114 4 жыл бұрын
.AddForce: Spaceship game, here I come!
@JustN4n0
@JustN4n0 4 жыл бұрын
Thank you! All of the tutorials I watched never explained how those work, and never understood until now, great vid! :)
@LostRelicGames
@LostRelicGames 4 жыл бұрын
Awesome Marcos!
@goodgamershow6505
@goodgamershow6505 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
@codinginflow
@codinginflow 3 жыл бұрын
Terrific explanation, thank you
@seballo2707
@seballo2707 3 жыл бұрын
Dude your videos are the best thing I've found on youtube about Unity.
@gareebdevelopers3079
@gareebdevelopers3079 3 жыл бұрын
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.
@LostRelicGames
@LostRelicGames 3 жыл бұрын
​►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 3 жыл бұрын
that brings up the assetstore only
@kevinmantao1357
@kevinmantao1357 3 жыл бұрын
The link is broken.
@sophiehealey4783
@sophiehealey4783 3 жыл бұрын
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.
@maliksaraanasim5404
@maliksaraanasim5404 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
@Kyjor_
@Kyjor_ 4 жыл бұрын
This is so practical! Helped me figure about an issue with my 2D character!
@muhamamdjamali1114
@muhamamdjamali1114 4 жыл бұрын
Awesome tutorial better than anyone i found on youtube described breifly and to the point keep it up man love u
@pauljoneseyboy9615
@pauljoneseyboy9615 3 жыл бұрын
I’ve been struggling to learn this stuff, with this video it just *clicked* thanks so much!
@muhammedalshameri801
@muhammedalshameri801 4 жыл бұрын
Finally someone explain what every function do. You were a big help, thanks man.
@ogibogi2004
@ogibogi2004 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 3 жыл бұрын
kzbin.info/www/bejne/j6umd2awl8uIe5I
@Alex-re3qm
@Alex-re3qm 2 жыл бұрын
only video I found that actually helped me understand what to do and what the code does
@JohnnyThousand605
@JohnnyThousand605 2 жыл бұрын
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 ;-) )
@user-wj3le7pn5n
@user-wj3le7pn5n 2 жыл бұрын
This is by far the best tutorial on moving 2d characters. Thank you so much!
@shamangrayson8143
@shamangrayson8143 Жыл бұрын
Thank you so much for this video. Really helping me understand some of the fundamentals better!
@someoneyoudontknow2704
@someoneyoudontknow2704 4 жыл бұрын
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!
@overlorde7526
@overlorde7526 4 жыл бұрын
There are just not enough tutorials on 2d movement, thank you so much
@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 3 жыл бұрын
kzbin.info/www/bejne/j6umd2awl8uIe5I
@TheSerphmx
@TheSerphmx 4 жыл бұрын
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 4 жыл бұрын
Nice one dude, you're a good man. Swing by the discord if you ever need to chat
@sethfleshman4137
@sethfleshman4137 4 жыл бұрын
This is literally epic, thank you so much
@axolotlaxel
@axolotlaxel 4 жыл бұрын
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!
@rlopera
@rlopera Жыл бұрын
Thanks so much. Brilliant start point to start learning.
@alexcernescu5868
@alexcernescu5868 3 жыл бұрын
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!
@THEspindoctor84
@THEspindoctor84 3 жыл бұрын
this is a great tutorial, and well explained!
@reblfist8849
@reblfist8849 4 жыл бұрын
Amazing video liked and subscribed thank you you are a very good teacher!
@andresabadiadeveloper1489
@andresabadiadeveloper1489 2 жыл бұрын
men, this is gold, thanks for this!
@kidscanvas4141
@kidscanvas4141 Жыл бұрын
Best video for beginners.but please it's a request to place your all videos on unity in a playlist
@jaskarnjass8548
@jaskarnjass8548 4 жыл бұрын
Awesome tutorial🤩🤩 .Please make a full course of your tutorials on 2d games. Keep the good work
@LostRelicGames
@LostRelicGames 4 жыл бұрын
Great idea! Thanks for your support
@usamakr
@usamakr 2 жыл бұрын
Thanks for this. Great content.
@abhishekdhiman6845
@abhishekdhiman6845 3 жыл бұрын
Really Appreciate Bro Thank a lot for this Really good Explain all techniques and their working❤✨✨
@Repanon00
@Repanon00 4 жыл бұрын
Great info! Very helpful!
@legendguitargamer
@legendguitargamer 3 жыл бұрын
Helped a lot bro! Thanks
@phantomclan3156
@phantomclan3156 4 жыл бұрын
Great Work! You just got a new subbed
@Tekkenandgaming
@Tekkenandgaming 4 жыл бұрын
thank you dude this was a lot of help!
@azueta9
@azueta9 Жыл бұрын
Awesome video thank you so much!
@shreyas908
@shreyas908 3 жыл бұрын
subscribed!!! no time wasted i thank you !!! your are life saver
@sunilshetty5510
@sunilshetty5510 3 жыл бұрын
Can you give me the script
@saifgames2468
@saifgames2468 4 жыл бұрын
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 4 жыл бұрын
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 4 жыл бұрын
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.
@hajee_talsy
@hajee_talsy 2 жыл бұрын
Thank you so much, I managed to understand how to finally make my square move
@LuisCanary
@LuisCanary 4 жыл бұрын
Very good video, I learned a lot, thanks :D
@LostRelicGames
@LostRelicGames 4 жыл бұрын
glad to hear that Luis!
@stoicalsilence
@stoicalsilence 3 жыл бұрын
Thank you for the explanations.
@khangteh
@khangteh 4 жыл бұрын
Awesome! Great Tutorial!
@MyPianoRoom
@MyPianoRoom 4 жыл бұрын
Thanks for upload this tutorial ^^
@auscan7739
@auscan7739 2 жыл бұрын
thanks! helped me a lot with my game
@LostRelicGames
@LostRelicGames 2 жыл бұрын
My pleasure, all the best to you! :)
@blockishgaming8459
@blockishgaming8459 4 жыл бұрын
thanks u deserve more attention
@tungstenelephant9849
@tungstenelephant9849 3 жыл бұрын
Thank you so much for this!
@8blitzgamer179
@8blitzgamer179 3 жыл бұрын
thanks for adding the code for it
@kirillkir6268
@kirillkir6268 4 жыл бұрын
Great video, thx!
@sakuraggg1533
@sakuraggg1533 2 жыл бұрын
helped me lot about coding
@amirrezahh86
@amirrezahh86 3 жыл бұрын
it was very useful.. thanks a lot
@georgeak4454
@georgeak4454 2 жыл бұрын
Amazing man
@soggybons
@soggybons 4 жыл бұрын
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
@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 жыл бұрын
Thanks Hari, glad to hear you are making progress! Wishing you the best on the path ahead
@emmanuelperez48
@emmanuelperez48 4 жыл бұрын
Excelentemente explicado, muchas gracias por la información, suscrito
@foreducation408
@foreducation408 Жыл бұрын
awesome video
@JC-jz6rx
@JC-jz6rx 4 жыл бұрын
this is great stuff, came from Reddit
@LostRelicGames
@LostRelicGames 4 жыл бұрын
Nice to see you JC!
@MEGA_TREE
@MEGA_TREE 2 жыл бұрын
So helpful
@Fictionart977
@Fictionart977 2 жыл бұрын
I have subscribed!!!
@JohnDoe-oh7gf
@JohnDoe-oh7gf 2 ай бұрын
I'm late to the party but enjoyed it.
@aceadamgaming405
@aceadamgaming405 4 жыл бұрын
Hey, I was wondering, I’m creating a kinda like pool style game, is it possible for it to be controlled by clicking on the sprite/then you select another position, and it moves?
@justahuman4862
@justahuman4862 4 жыл бұрын
thanks for the tips.
@arnolditdang3791
@arnolditdang3791 3 жыл бұрын
i have understand physics thank youuuu!!!!!!!!
@AirskiiMusic
@AirskiiMusic 4 жыл бұрын
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 :)
@hercules5546
@hercules5546 4 жыл бұрын
awesome, ty so much !!
@zekiozdemir420
@zekiozdemir420 3 жыл бұрын
thank you
@Cubic_Gaming
@Cubic_Gaming Жыл бұрын
8:00 could be used for moving through a river which is flowing into the opposite direction
@Perfectbeing1045
@Perfectbeing1045 3 жыл бұрын
I feel that you will be the next brackeys.
@CrimsonEverFrost
@CrimsonEverFrost 3 жыл бұрын
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
@HeilmwaterStudios
@HeilmwaterStudios 4 жыл бұрын
HELPFUL
@echratus
@echratus 3 жыл бұрын
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
@wirrexx
@wirrexx 4 жыл бұрын
subscribed and Liked!!
@lee1davis1
@lee1davis1 4 жыл бұрын
Could ypu do a tut on wheelcolliders and grip or friction. At ceetain speeds my cars will not turn.
@alvarosanchez8066
@alvarosanchez8066 4 жыл бұрын
Just Thank You.
@athvgaming4959
@athvgaming4959 3 жыл бұрын
thanks a lot
@skippynik6003
@skippynik6003 3 жыл бұрын
This is the best movement related tutorial Ive ever seen on KZbin . I have a small doubt, why physics related stuffs are kept under FixedUpdate() instead update() ?
@sapazu
@sapazu 3 жыл бұрын
FixedUpdate() is synced to Unity's physics engine
@skippynik6003
@skippynik6003 3 жыл бұрын
@@sapazu Thanks man .
@CreepyUncleIdjit
@CreepyUncleIdjit 4 жыл бұрын
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 4 жыл бұрын
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 4 жыл бұрын
@@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.
@wolkenfarmer
@wolkenfarmer 4 жыл бұрын
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 жыл бұрын
@@LostRelicGames Helped! Thank you. :) However.. it confuses me, that it wasn't selected automatically, because I installed VS through Unity. xD
@keziasunny4129
@keziasunny4129 2 жыл бұрын
Do big animation movies include coding? Or only in games? In animation making app to move a character like that I have to draw multiple images of that in different places to look like it moving.
@tastyham
@tastyham 4 жыл бұрын
That's interesting and much more understandable now. But do you know how to make actual 2d movements with a force that slows the player down after he moved? I got that in my game but it doesn't seem to work properly with the jump and slightly gets into walls when pushing on them.
@bramvangool8224
@bramvangool8224 Жыл бұрын
Great!
@ElboxD
@ElboxD 2 жыл бұрын
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.)
@Wolhellm
@Wolhellm 2 жыл бұрын
how would I make the character jump/go up. I'm gueessing ou change somthing to do with the vector, but I can't find anything about it.
@peacesafe3087
@peacesafe3087 3 жыл бұрын
I'M IN 5:00 AND I THINK YOU ARE A "LEGEND"
@mariuszkrawiec3204
@mariuszkrawiec3204 4 жыл бұрын
super cool cheers
@rezazolgharnein7609
@rezazolgharnein7609 2 жыл бұрын
Hello, please make a video about the player pulling and pushing the block
@silverhand4468
@silverhand4468 3 жыл бұрын
thanks man i am working on android game and i'm confused about what controller to chose, any suggestions.
@briacovidiu4845
@briacovidiu4845 2 жыл бұрын
finally someone that tells us why tf we do what we do
@nihatheybtov5956
@nihatheybtov5956 3 жыл бұрын
İ used velocity code but my character just jump one times why? Probably i didn't write code correctly
@danielschulz7391
@danielschulz7391 3 жыл бұрын
Did you left vector2.Lerp() out for a reason? Is it some kind of code smell for moving? I'm trying out online multiplayer stuff at the moment and for me Lerp is the way to go to handle lag problems without flickering.
@val_ience4993
@val_ience4993 2 жыл бұрын
this is the only video where they explain stuff
@TheDeadlyDalek
@TheDeadlyDalek Жыл бұрын
Which technique does your game "blood and mead" use? Thanks!
Breaking up Code in Unity (Important game dev tips for beginners)
18:36
Lost Relic Games
Рет қаралды 123 М.
Better Jumping in Unity With Four Lines of Code
12:47
Board To Bits Games
Рет қаралды 817 М.
Как быстро замутить ЭлектроСамокат
00:59
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 13 МЛН
1🥺🎉 #thankyou
00:29
はじめしゃちょー(hajime)
Рет қаралды 80 МЛН
Super gymnastics 😍🫣
00:15
Lexa_Merin
Рет қаралды 76 МЛН
小女孩把路人当成离世的妈妈,太感人了.#short #angel #clown
00:53
A Perfect Jump in Unity - A Complete Guide
17:05
Press Start
Рет қаралды 75 М.
2D Movement in Unity (Tutorial)
21:09
Brackeys
Рет қаралды 3 МЛН
TOP DOWN MOVEMENT in Unity!
22:30
Brackeys
Рет қаралды 1,2 МЛН
Grid Based Movement in Unity
18:35
gamesplusjames
Рет қаралды 180 М.
This Famous Game Designer Had A BAD Steam Launch - My Thoughts.
10:03
Lost Relic Games
Рет қаралды 77 М.
Unity Movement [RigidBody vs Translate]
9:00
Press Start
Рет қаралды 282 М.
How to deal with SLOPES! in Unity 2D using built in Physics
30:07
FIRST PERSON MOVEMENT in 10 MINUTES - Unity Tutorial
9:58
Dave / GameDevelopment
Рет қаралды 1 МЛН
Как быстро замутить ЭлектроСамокат
00:59
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 13 МЛН