How to make a Video Game in Unity - MOVEMENT (E03)
Vložit
- čas přidán 7. 02. 2017
- In this video we learn to control our player!
● Download scripts, assets and project files for this course: devassets.com/assets/how-to-ma...
● Developer Forum: forum.brackeys.com/
Difficulty of lesson: Novice.
····················································································
This video is part of a mini-series on making your first game in Unity.
····················································································
► Join Discord: / discord
♥ Subscribe: bit.ly/1kMekJV
● Website: brackeys.com/
● Facebook: / brackeys
● Twitter: / brackeystweet
····················································································
► All content by Brackeys is 100% free. I believe that education should be available for everyone. Any support is truly appreciated so I can keep on making the content free of charge.
····················································································
♪ "Too Cool" Kevin MacLeod (incompetech.com)
Licensed under Creative Commons: By Attribution 3.0 License
creativecommons.org/licenses/b...
♪ Baby Plays Electro Games
teknoaxe.com/cgi-bin/link_code...
Hearing "so let's save this" and pausing it in time to write his code before he opens the unity window again should be considered an extreme sport
I would add to your comment on "extreme sport" and go as far as to say. Typing at the same time he writes his code, without pausing the video, should be considered an "extreme sport".
@@karlembeast Noob, I typed the code before he even spelled the word "Unity"
The boring programmer Then what the French are you doing here? It sounds like you already knew the code before watching the video
@@thesodanerd3205 I was sarcastic.
Caleb Little somewhat of an r/whoosh
That feeling when you Go from wondering, "how the hell do you make things move in unity with code?" to actually making it happen :D feelsgoodman
oh yeah
so true!
The best feeling!
to that moment where you make a new game and have to come back to this vid bcs you forgot how to code moving
Is started giggling like a toddler
I just visited Brackey's asset store, and I must say, all of those beautiful assets? for free? I am literally gobsmacked, I am also a blender user and those assets on his store could easily sell for 50-100 $ *easily*. and even the most expensive price you can choose is 20$? This man is a literal God, he deserves so much more recognition
I literally cannot stress how kind this guy is, its unbelievable
He sure is a man of culture
he is providing it for free but sure it is better to donate and support his work if you can .
@Carlos Basulto he isn't like that, he generally likes to help people out.
I know i use blender too and there are asset stores with like a 40$ a month subscripition so this is super cool to find
200th like
"Getkey" is used for if the key is held down while "getkeydown" is used for if the key is pressed once
You're welcome
thanks
Sir, what should we write after the "GetKey" so that we can move our player by pressing the arrow keys present on our keyboard.
Can u plz tell me!?
@James Thwaites same thing i said just simplified
@@Sentoefn life saver
You’re*
Brackeys : talks about variables
me with my 1 year of scratch experience : "I am four parallel universes ahead of you"
Me too
xddddd
same
loll same!
Me who is in bed and wanting to start unity the next day: I am 4 parallel universes behind you
Here for the people who wondered why there is an f behind the 2000:
Both Unityscript and C# use "f" to indicate a float and "d" to indicate a double. The difference is that double is the default for C#, but float is the default for Unityscript. So if you use a decimal number but leave off the "f" or "d", then it will use the default for whatever language you're using.
This needs more upvotes, thanks, so I guess it's better to always use them so you're never fucked up by your environment.
@@xord1946 this, loading the entire game at once, unused libraries, tying the game's physics to the framerate et sic in infinitum are all things that yandere dev did before (and got pissed at people rewriting his code) honestly it's more fun to look at the effects these things had on the games than playing them, but it is the best way of showing how this affects your project so you'll never get fucked over by your own stupidity.
all hail general sosigwater
are you sure it doesn't want us to pay respec
imagine leaving a comment on a video you didn't watch. 6:23
@@reallylegit5145 He didn't really explain why the f is behind the number, he just said that unity complained. So maybe you should watch the video again.
Thanks a lot for your job! I am proud of that youTube platform has such a great professionals :0
hey bro I need some help here's my code:
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public Rigidbody rb;
public float forwardForce = 2000f;
// Update is called once per frame
void FixedUpdate()
{
rb.AddForce(0, 0, forwardForce * Time.deltaTime);
if (Input.Getkey("d"))
rb.Addforce(500 * Time.deltaTime, 0, 0);
}
}
The problem lies within the if statement
it says that "Input does not contain a definition for Getkey"
and that "Rigidbody does not contain a definition for addforce
@@MalalisJyleErwinD i think you missed a step in ep 2 check again
@@MalalisJyleErwinD using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public Rigidbody rb;
public float ForwardForce = 2000f;
public float SidewaysForce = 500f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void FixedUpdate()
{
rb.AddForce(0, 0, ForwardForce * Time.deltaTime);
if (Input.GetKey("d"))
{
rb.AddForce(SidewaysForce * Time.deltaTime, 0, 0);
}
if (Input.GetKey("a"))
{
rb.AddForce(-SidewaysForce * Time.deltaTime, 0, 0);
}
}
}
@@MalalisJyleErwinD you wrote Getkey instead of GetKey (its case sensitive)
@@MalalisJyleErwinD just retype it
It's incredible how this amazing tutorials are way better than a whole semester at a university
He puts the " f " at the end of public float numbers to pay respecc
@@kindersmith8407 this is gota be a joke ,hes just pointed out your mistake
s
He puts it to define the type
Kinder Smith C sharp is case sensitive. Use "Time.deltaTime"
@@kindersmith8407 Time.deltaTime
It's funny how every video has so many less views than the previous. Gotta stay motivated
Basically every video series about anything ever (gameplay or teaching , both got same problem)
Unfortunately we're in a time where it's about "I want it NOW" rather than learning, waiting or earning it. I think many people expected to make a game after 2 or 3 small tutorials and when they realized it takes more work, they gave up. Kinda sad, really.
@@1NabbinatoR thx for the idea XD
its too hard to continue
Or maybe it is just because - as every tutorial on YT - it is casually and intentionally watched (and re-watched) many times over the course of years, so natually the older videos will have more views.
I know you're not making videos anymore, but I just wanted to say that you are a saint for uploading free to use assets and files for your series. You are a beautiful person.
Hii bro
I know right. new to unity and its so helpful to get free assets just to test things with
I love how he gives us the basics and explains it really well, and then every other thing he explains in understanable
Is it just me, or has the quality of these videos become astounding?
Wow, thanks a lot! Been putting a lot more time into each one :)
Brackeys no problem! I've been watching you for quite a long while!
What Number If You Want To Do Backwards Force Please Reply Brackeys
simple put, give it a negative number, if you are only asking for going backwards, it should work fine
Its simple the direction of backwards is -z
So do this (0,0,-BackwardSpeed)
This is literally the first time i've used unity and I already feel like I can make the next god of war game, these tutorials are so damn good
Don't be silly. You can't make next God Of War game.
Sony would sue you for using their title.
@@intru3915 //not gonna lie they got us in thr first half
sony will sue you
@@daniellordyt Ok, but Undertale, Stardew Valley, Cave Story and MINECRAFT were all developed by one person.
Telling somebody it takes a while or it's difficult to make a game by themselves is fine, but stop telling people they just "can't do something". That's not helpful.
daniellord ok but shut up and let the person have their moment thanksbye
5 years later and this code still works
it didnt for me though :C
@@tamajthelegend4232 damn how come?
Wait, it does not work?
@@spartan112 it does for me but not for tama
@@Icanthandle938 When I multiply it with Time.deltaTime, it does not work
superb tutorial series, I always wanted to learn how to make a game but completely dismissed it out of fear of learning code. But this breaks things down in a way that actually starts to make sense immediately, which is motivating
I laughed every time I successfully coded the cube and watched it run away. Thanks for the awesome course.
Same! I giggle and tell my fiance to come see every time I successfully code 😂😂
sameeeee
I showed it to my mom and she said that I am wasting my time... Pain.
when i press "a" ,it doesn't move left, any help please!!
Coding your own games is easier than you think. You know, you should take this online Unity course.
i can never tell if it says Udemy or Unity lmao
@@mattb6903 same
@@HHHHH-vm5kc just stick with youtube. Its better to research on your own than do what other people tells you to do.
@CJH technicaly yes
I got this ad 1,000 times lol
I'm headed to your patreon now. This is the absolute BEST, most helpful tutorial I have gone through. I've wasted so much money on courses all over the web and none of them are this great. Thank you so much
Dude out of all my years on youtube this is these videos are the ones i most enjoyed. Good job my guy
Me, a year ago: "I'm going to watch this for fun!"
Me, right now: "Wow, I finally have Unity installed! What should I make?"
Help makeing timesplitters rewind :)
U da man, Cat Man.
Anyways I always wanted to get into Unity whilst I was in my GameMaker Phase and I had this similar feeling like you lol.
Wow Same Man!
Yooo same
Add block and BEAN
I learned more programming from this mini-series than in an entire year of studying computer science, good job man, your ways of teaching are ON POINT.
There's something wrong with how you study computer science then
@@ethanma1722 fr lmaoo
U study in bangladesh or sth like that?
I studied in khan academy programing...
Didn't learn much
Same
I’m new to these things but the fact that they made their assets depends on your option, if you want to pay or not, is a very generous act by them!! Nice guys you’re the best for real🙏
for those who want to optimize it using the method brackeys said during the end of the vid, here is the code to do it:
private bool dKey = false;
private bool aKey = false;
private void Update()
{
if (Input.GetKey("d"))
{
dKey = true;
}
else dKey = false;
if (Input.GetKey("a"))
{
aKey = true;
}
else aKey = false;
}
void FixedUpdate()
{
rigidbody.AddForce(xForce, yForce, zForce * Time.deltaTime);
if (dKey)
{
rigidbody.AddForce(movementSpeed * Time.deltaTime, 0, 0);
}
if(aKey)
{
rigidbody.AddForce(-movementSpeed * Time.deltaTime, 0, 0);
}
}
would you not have the else if(aKey) as an if statement? that way when you hold down both at the same time it doesnt just think you're only applying the force of holding down the d key
Thanks for copying the code here, now I don't have to search outside to look for how to do it properly.
@@Gabriel-zy6xv lol sorry for the late af reply, yeah ur right, I changed it
THANK YOU SO MUCH
Thank you so much
Thanks Brackeys for making videos for us
You are very welcome! :D
Great tutorial mate, keep it up, thank you so much!
Brackeys really nice videos. Would love to see how to make ropes like the once used in some platformers to swing from platform to platform.
I really like how you explain everything so that everyone understands
I love your pro pic its so funny
ha I still don't understand anything
Helped me learn programming very well.
@@mrebbesen You Should focus, its easy
brackeys even though you have quit youtube you wont be forgotten you have helped countless people make games you have already gave people thousands apon thousands of dollars just because of your tutorials man good job dude
Fantastic, of all the tutorials I've seen these last few days, you are the only person to explain why "f" is used in float values.
Here are some requested topic which I'd like to see:
-Collision checking
-Health variables with particle effect on death
And as always: This video was absolutely great! :D
if you need help with collision i can help
That's very nice!
I'm just new in coding in C# and barely know what a variable is...
Just kidding :D
But still I'm very bad at coding but if you could help me with collision-checking (only a technique, maybe), that would be awesome! :D
Just use this function: void OnCollision*x*(Collision col)
'x' could be "Enter", "Stay", "Exit".
Just make sure you add a Collider to the GameObject and a Rigidbody if necessary.
Here's an example of the function:
public void OnCollisionEnter(Collision col)
{
Debug.Log("Something Collided with me!");
}
if you want stuff with particle effect on death, Brackeys has a video in his Multiplayer FPS series that shows death and spawn effects :D
Tornado Thanks for the reply, but I have another question: What is "void"?
I know the meaning as a word, but in programming, how could you describe it?
I just don't get it :/
You're such a great guy for having a free option for everything.... that's rare y'know. Because you made it free i'm going to pay for it in the future :D I love your videos!
This video is so cool!
After you showed how to code for left/right movement, i wannted to try to get forward backwards and jumping on my own!
it was so much fun to learn
Same thing is happening to me
trying to start making games
and you are my savior, you deserve a sub
and the free assets just makes this situation 100 times better
youre a legend
I'm so happy you made this tutorial when.
I tried to get into Unity I had badtime to figure out a tutorial to know the basics of Unity.
I like your content keep with it Brackeys!
Finally a video that explains what variables are in a concise manner. Not even my old teachers knew how to explain variables the way you did.
I'm finding this over 4 years after it's been uploaded and it's still been very very very helpful. Just got yourself a new sub!
I will always return to this as the videos that started my career.
And? Did it work out?
@@NoSp1ne ok when i said career i didnt mean i immediately started making money but what i meant is that this is what got me into coding. first in unity, then i went to console apps, WPF, etc. still a novice, though
you are a living LEGEND! you make all of this for free and really easy to follow and understand thank man I love your vids!!!
Thank you so much for making these videos! I started off as some dude who had all these ideas for games but no way to implement them. Every tutorial I found, had something missing and I'm not sure what. Being able to take the crappy 3d models I've been making and watching them move from my controls, showed me just how far I've come. To everyone else, I'd recommend taking notes on these vids so you don't have to keep rewatching them. Here's my notes so far: Unity Notes (Brackeys)
Video 1/Intro
Controls:
Middle mouse to zoom.
Hold alt to pan around and to use WASD.
Scroll wheel to zoom in/out.
F to focus.
Rotate tools and everything, are top right or using QWERT.
Rigidbody component to get the item to use the game’s physics.
Box collider: stops item from colliding with other objects. Can set an object to collide like any item regardless of its mesh.
Mesh is how you see it.
Video 2 Programming
// are comments that are ignored
C# script edited in Visual Studio
C# is case sensitive and end all lines with ;
To add script: go to component and choose Add Script.
Must drag script to item before it can be used.
Void Start: Runs script when game starts and only once.
Void Update: Runs script per frame
Console notes: Debug.Log(“Message here”);
Above function: public Rigidbody rb; (Defines Rigidbody as rb so we don’t have to keep typing it.)
On the inspector tab, anything with that script applied to it, will now have an extra slot in their script where you drag the rigid body component to. So when you write any code referencing rb, it knows you mean Rigidbody.
Under void start:
rb.useGravity = false;
Replace rb.useGravity = false; with rb.AddForce( 0, 200, 500); // x, y, z
Erase entire start function then,
Under void Update:
rb.AddForce( 0, 0, 200);
But how much force you get, depends on your frames which differs from computer to computer.
Add in rb.AddForce( 0, 0, 200 * Time.deltaTime);
Force wasn’t strong enough so change the 200 to 2000
Change void update to FixedUpdate
Boolean is (if-then) statements.
Video 3: movement
Freeze Constraints/rotation under Rigidbody
Using physics material (Create>physics material)
To edit a value without going into the code, we use variables:
To make it editable, we type Public before the line.
Example: public int. Health = 10; //This tells the game that health is both an integer, a variable and is equal to ten.
I can then edit Health = 5; // or w/e I want, later on.
Debug.Log(Health); // displays health in console
Next example:
First do Public float forwardForce = 2000
Using Public makes a variable editable
After that, you must go down to the rb.AddForce( 0, 0, 200 * Time.deltaTime); and change it to rb.AddForce(0, 0, forwardForce * Time.deltaTime); //Now the game knows that the forward force it’s exerting, is equal to the variable you edit in the inspector.
Player controls/if-then statements
!= (not equal to
if (Input.GetKey("d") )
//Only executed if condition is met
rb.AddForce(500 * Time.deltaTime, 0, 0); //This is your "Then" statement
X axis is right and left, so -500 is right, 500 is left
Sometimes Unity will complain if a float number is not followed by an f, like 2000f
:O
Would be amazing if someone could type this up in LaTeX! 👌😂
what do you do in your free time lol
Thank u good sir for the notes! 😊👍
Thank you!
For my first 3D game engine, you are doing a phenomenal job explaining the basics! Thank you!
This lesson is amazing. Its so easy to follow and Brackeys makes it fun. This is the best coding tutorial I have ever watched.
This man is such lawful good energy and it makes me have faith in humanity. Making ur products a pay what u can afford. You and elon musk man, you too are here to make the world better ILY
bill gates???
Just wanted to call out, you're a great teacher dude, you really are. I've known programming for years, but your approach to teaching vars and everything is spot on.
Seriously great work!
I love how he keeps everything free and accessible, thanks you are an angel
Thank you for doing these tutorials :) I've programmed in C++ for 2 years now, but I was always scared to try C# and Unity, and get into the "visual" part of programming, since I never really found something to explain from scratch
This tutorial seems like the perfect opportunity!
I’ve been trying to figure out how to make video games for my entire life, it has always been my passion, and finding these tutorials was a blessing, so thanks!! I just downloaded unity (again lol) and im gonna put alot of work into this. Thanks for keeping this entertaining!
The sheer quality of these free videos on youtube is insane! You honestly deserve to be one of those pro teachers for $300 courses on udemy for just how approachable your videos are! Thanks so much from me and I'm guessing the literal millions of people you've helped
this guy teaches so fast that every second is full of detail which i literally love it 😍😍
Brackeys! Thank you so much for creating that asset repository! I'm working on learning unity and gamedev, and some of your fantasy assets will make excellent placeholders while I learn modeling! I cannot thank you enough for this service you are providing!!
As a player(and a somewhat curious programmer), I finally knew what's happening behind when I'm missing those inputs in low framerates. Thanks for the great tutorials.
if your watching this tutorial and feel like giving up trust me don't, you'll get there eventually and once you do you will be glad u didn't stop.
It takes a master to explain complex topics and make it easy to understand. Thanks for the vids
I was a computer engineering student 20 years ago... I never had so much fun accomplishing anything like today... thank you a lifetime...
Wow! I don't think there is anyone better on CZcams that explains Unity like you! Great job!!!
"And it already starts to feel like a game" YESSSS! As a visual artist this made so much sense to me than the Console printing method.
I love when youtubers make a important aspect to coding something related to real life.
I've been using GameMaker Studio 2 for a few months now and C# and GML share a lot in common. Thanks a lot!
It's such a terrible feeling to get stuck with errors in the codes and no idea what to do, but such a great feeling when you finally figure it out and fix it.
Man these tutorials are incredible I really feel like i'm learning something from them 10/10
This is fantastic man. Thank you for doing this. We really are living in the golden age of learning.
im 13 and had started coding this year man and this is the first really good coding lesson after 2 years of surfing the wed
“You can pay whatever you like for this”
That’s how you get subs without asking 😘
Online Courses on Udemy: ✋😤
Brackeys’ Tutorials: 😀👌
Thanks, Brackeys!
These tutorials actually help a lot more than you probably think.
I greatly appreciate the time you put into these tutorials. They are helping me out a lot for a series made 5 years ago. :)
Unity- 1-Brackeys
2- Sykoo
Blender- 1-Andrew(Blender guru)
2- CG Geek
How many agree with me?
G develop-wishforge games
@@SunilNmb i never heard about this channel
but with funny game dev vdos dani is the #1
Hey man, just want to express my deepest gratitude, for your AMAZING efforts with teaching an expansive topic, in such a fairly simplistic manner. Just pushing until I become more financially stable, then I'd LOVE to support you via Patreon 🔥
Love what you're doing & implore for you to keep going 🙏
- GamerTank
This is so easy! I tried this multiple times before with other youtubers/guides and somehow always got lost, so far I've been able to keep track easily with you though!
I am 12 years old and these tutorials help me so much , I do not understand completely whats going on but still I learnt a lot about C sharp and game development , thank you soo much for these free tutorials
The best Unity tutor of all time
I'm loving these tutorials! Thanks alot!
I bought a course one of the top courses in udemy and it was nothing comparing to your videos, REALLY GREAT JOB MAN
Watched your first three videos. Had an absolute blast, thanks for all the help!
This man is a fucking legend, thank you for taking time to do this. You're too good for humanity!!!
Wow, a udemy ad on this free turtorial.
i saw that as well lol
Just despicable...
@@aaronfidelis3188 yeah how despicable. guy gives free lessons, free assets and has the audacity to have ads on his videos, shame on him for getting CZcams to fund his time and effort.
@@joshawafrith4797 That isn't what he meant, he meant that Udemy is bad for trying to take views away from him by advertizing their courses. It's not a problem of there being monetization on the video.
This is so helpful. I have no prior experience with any of this and I'm learning easily
Watching your tutorials in 2020 and it's awesome.
I was able to do this tutorial without one error! Yahoo! I think I will have to invest in an additional monitor, switching from Unity to CZcams to Visual Studio is time-consuming.
i feel you hahaha
I open CZcams in my tab
bruh your alt tab game is WEAK
Brackeys keep making videos they're awesome what I like about you is that you explain well and you don't just give us the code keep it up!!😄😄
I already knew js and the way you explained it made C# really really easy for me
I watched this episode in 2022 and you made it so understandable to me that I went ahead and added a few extra movements keys to make it feel even more like a game more, thanks Brackeys : ). (I did this ahead if time btw)
209 likes and no dislikes? Wow, you make really nice content.
This is a really helpful channel, definitely subscribing and liking.
"he starts rotating and jumping"
Me using a sphere: I am four parrarel universes ahead of you!
Sorry but not very funny.
Please don't call me a boomer
This is really funny... I did the same, and it was really fine without adding physic material
@@bbgamingplay1511 you’re not a boomer, just kinda dumb. Why bother replying just to say ‘not funny’ and add nothing of value to the replys. We do not need to hear your personal opinion. At least if you call it funny then the original commenter gets to know their comment had a positive impact. Now I’m not saying ‘if you don’t have anything nice to say don’t say it’, feel free to express your opinion, but at least do it in the form of constructive criticism instead of just a negative comment (e.g ‘I do not find this very funny because.......’ then you could explain why you don’t find it funny (whether it’s just not your sense of humour, not very original, etc)).
Man, you're such a gem... Always feels so nice to see you with a smiling face in the end. You're doing great, keep up!
So I really just started coding a short time ago, and it's quite a challenge to begin learning. I actually started a college coding class in high school to learn because my school doesn't provide how to code. In the class I have been struggling and often felt unable to write what I deemed important down because the classes are online, so they more or less went over my head about a week and a half in. I picked up the first couple of these videos but I lacked motivation to keep at it, but after the puzzling of my recent classes I figured this might help familiarize me. In this episode you have motivated me past daydreaming game ideas and I am now taking notes on your videos. Thanks.
Holy cow! Tanks dude! This makes my life soo much easier, Even with Java experience this is understandable
The best tutorial ever, even my grandmom can understend it.
Zed main?
ikr
you underestimate grandmoms
Understending is different
no she can't
Big like. I did understand it. I even tried adding the "w" key to go forward, and it worked!
this is amazing, i can see that you really put time, effort and love into these tutorials, thanks for that!♥
It wont work for me ive got the error “the variable rb of playerMovement has not been assigned
Edit:i put none (rigidbody) to player (rigidbody”
Yea I had the same problem this fixed it though thx !
what do you mean
Hi I am still a little Can fuzed can you please explain a little more
@@hunniedew5037 add the component rigidbody to the script like he does
I dont get the mistake u made, can u clarify?? im getting the same error
i love you dude i am addicted to your videos and i love this more keep the good work
Best tutorials I've come across so far! Love them!
All the other tutorials I have watched are nothing compared to this, keep it up and thank you!
you make everything so clear and I understand all the code THX DUDE :)
Glad you think so :D
Third😅
Really good video!
Waited so long for this!😁
I loved that you added the extra challenge at the end! I managed it myself :)
I've been looking for some coding tutorials for Unity cuz I kinda wanted to be a game dev and everything was so hard but... when I saw this vid called how to program, I started my own program and this started my life as a game dev. A couple of months passed and then I saw this vid called "GoodBye Thank you for everything!" he stopped uploading. and I was kinda sad but happy for Brackeys. Hope he gets his free life. He will be my inspiration forever:).
This went perfectly well!
thank to the youtube gods that we can watch videos at x.75
Shreerang Vaidya I played this at 0x Thank the CZcams gods
Well, thank you as well for that info.
10nk u, I ddnt know, from now i'll watch tutorials on x1.25 or more.
Thank this god called Brackeys!
2 days into your CZcams course, God Thank you so so much
You're the best bro,Thank you so much for sharing such priceless information .I'm getting motivated every time the code works and though sometimes it doesnt, Im not giving up.