How to make a Video Game in Unity - CAMERA FOLLOW (E04)
Vložit
- čas přidán 14. 02. 2017
- Let's make our camera follow our player!
● Download scripts, assets and project files for this course: devassets.com/assets/how-to-ma...
❤️ Donate: www.paypal.com/donate/?hosted...
····················································································
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.
····················································································
♪ Baby Plays Electro Games
teknoaxe.com/cgi-bin/link_code...
Hey guys! I'm glad you guys are liking the series so far :)
I try to put as much effort into each single episode as possible! I also see a lot of you commenting that you would like to see more videos each week. While I would love that too it just isn't possible for me at the current time. Making these videos takes A LOT of time and while I try to put all my focus into the CZcams channel I do have to dedicate myself to client work here and there in order to pay the bills. If you would like to see more videos I would suggest becoming a Patreon Supporter. This allows me to put more time into the channel without having to worry about the financial aspect. You can do so here: patreon.com/brackeys
Thanks for being so awesome and supportive! Can't wait to bring you guys more content :D
Gr8 series...keep going buddy
Brackeys, Is there anyway to donate you by SMS ? You are doing great work, and I actually feel like, I can make games. BTW. sorry for bad grammar XD
Lol 666$ per week :_:
Brackeys i have published an app in play store after learning from your videos. Beat My Score. an endless game when troll faces irritate us while playing. it will be soon on appstore. please make a review video or a short video showing my app in ur videos
Thanks
Anyone else get that feeling of satisfaction when the code works
Totally
anyone feel the frustration after spending hours debuging and finding out a letter was lowercase
Same, its like you are a pro gamer.
@@counterscam6547 that is the worst feeling in the world.
Yeah
I would rather have 100 simple and short tutorials like this than any other way
Found this one after following a tutorial that took me over 8 hours, tutorials like this with 10 minutes per part are great!
You are absolutely right. It is best to learn in small steps and always with a practical example in front of you so that the information is 100% understood. Great tutorials!
ikr
Ikr
666 likes... NICE
6 years and this is still so freaking helpful. I'm grateful your channel exists
yes
Yeah
ye
I'm seriously having the best time doing this.
Every step is working as I go, and I'm building confidence as I go.
Thank you so much.
Ikr.
Hell yeah let's keep at it
same
I am smiling every time I do any kind of little thing is just so...
Just feels good
sameee any time i've ever tried doing *anything* creative it ended up horribly but i feel like a pro when i do this lol
i watched this 3 times while my unity loaded
@Asphyxation UNITE
SHITPC! i have an laptop that just works
@@gamingmetjayden1361 grammar much
jesus
I watched 4 episodes while I was downloading unity not including the intro to the series
the camera code is
using UnityEngine;
public class FollowPlayer : MonoBehaviour
{
public Transform player;
public Vector3 offset;
// Update is called once per frame
void Update()
{
transform.position = player.position + offset;
}
}
for anyone who can't see the video at the moment
edit: ah yes i figured it out, after dragging the script to the camera and selecting the camera, there should be a slot where you can drag the cube on, and like Jonathan said change the offset a little and you should be good to go.
Thanks. And also don't forget to adjust the "offset" values in Unity so that you can actually see the cube :) Otherwise you'll be inside of it. Just click the camera and put like x=0, y=2, z=10 or whatever you think works well.
@@jonathanlindqvist570 hey bro can you see the video?
@@cancerina4474 No I can't see it either unfortunately. But I fixed the camera that way, perhaps there are better ways :)
Edit: just use the code provided above by Patrik Puskas, add a script to the camera and put the code there. Then go in to Unity and adjust the offset values when you have selected the camera. Hope it works!
@@jonathanlindqvist570 do you got a discord so i can ask you something because i got stuck?
@@cancerina4474 sure, give me your discord tag and I'll add you
4 years later, even after retirement, his tutorials are helping so many such as me. thanks, dude
I'm upset because the video isn't working anymore.. it hasn't been deleted, it just doesn't work. I've refreshed the app, restarted my device, switched devices, nothing works...
@@HazardIg same, it doesn't work for me
@@lunathecat4318 okay so it's definitely a youtube problem then.. well I guess we'll have to learn by ourselves lol
@@HazardIgmine is working
simple and clear I love what you're doing
mr.MYSTERIOUS,YT yea
UDEMY is like a psycho ex who just keeps coming back even though I’ve already reattached with Brackeys.
I remember getting jealous I couldn't have Udemy but turns out, like, YT tutorials are mostly better...
@@NoOffenseAnimation The classes are like ten bucks a piece.
Ashley, that's awfully specific, you okay?
@@nothingtoseehere6142 10 bucks a breath u take in them lol
It's been 4 days I've discovered this channel and I'n already in love with game development. You make your videos very interesting and educational. Very well done.
and its been 5years for me and this video is really helpful.
During Quarantine : I'm bored..
Also During quarantine: Learning unity via tutorials
Who else is here during the pandemic?
Haha me too, have fun coding ;)
i already knew python thanks to my CS class but i prefer making games which isn't as easy with python so these videos have really helped, i'm also doing this @ 02:15 so i'm not getting up in the morning lol.
Me. I got inspired to make a game, so here we are.
me too
yup..
the most legendary and beginner-friendly game- dev tutorials I have ever seen on youtube
thank you, bro
i hope u succeed in ur youtube and game development life
the thing I love about these tutorials is that they are free. I was watching some other CZcamsrs on how to do this (no offense to them but they couldn't teach crap), then I come here, watch the first tutorial and... to say the least... I'm instantly hooked. these are *FREE*. I've never taken a paid online course but its gotta be on par with this AT LEAST if I'm ever gonna buy them.
*This guy has the right idea about teaching beginners.*
About 2 months ago I decided I want to make at least one video game this summer. You motivated me to start right now, and I'm super happy that I can learn really easy with your tutorials. I just wanted to say THANK YOU for putting so much effort in these tutorials and helping others out, I really really appreciate it
I've been trying to learn the basics as a complete beginner, and I've started and stopped on different tutorials and courses probably 5 times in the last few months, as I usually find the instructions to be difficult to digest with no relatable experience. But watching your series is a breath of fresh air. I finally feel like I'm getting somewhere. I just wish I started learning when I was younger, as my 30 year old brain is like a sieve at this point.
Just in case someone like me gets lost:
If you added the script and all, make sure you added the component to the Main Camera and not to the Player. Dumb me did that, and I spent 10 minutes trying to figure that out.
Damn mate, ain`t you an angel?
thank you so much
@@aterr learn.unity.com
go download some tutorial using IDM until june 20th
THANKSS
haha i was about to lose my shit. Thank you so much!!!!
Thank you so much for these easy to understand tutorials. You’ve somehow made me excited to learn more code. You’re tutorials are the best!
I love how you are actually teaching the basics people like me want to know. I can now apply the same basic information to play around and make the light a spotlight that follows the player.
Even though it goes fast, it is logical enough to follow, and your face and voice are super friendly which makes it a very pleasant learning experience.
These tutorials are amazing, I took programming sometime ago so this is a nice refresher!
For those using this as a reference or wanting to review specific parts
of the lesson, here are some time-stamps of interest:
0:11: Setting the camera's parent.
0:49: Writing a script to control camera movement
1:25: Accessing the Transform of a different object
2:55: Setting an object's position to match another object's position
4:07: Adding an offset to the camera follow for a 3rd person view
Well Thank You
it's so unbelievably exciting to wonder about the different things you can actually do with these tools, and knowing so little about it makes it even better,
letting your mind race and wonder what could be made.
I just wanted to say you seem like a really great person and clearly, it shows, you always have a smile on your face like you are so excited to teach us and honestly it makes me so motivated to keep learning, so from the bottom of my heart, thank you so much for these videos!
Thanks Brackeys again.Keep doing what you're doing.You are the man bro.
Thank you, will do! :D
90
Amazing, you explain everything so well. Thanks, can't wait for the next episode!
Thanks a lot, glad you like it! :D
Oh no it’s 70!
@@bluestareverything9716 im from the future its 115
@@fatmasayah109 im from 19 hours in the future it is 116
@@efelk1039 its 119
I love how he seems always excited to teach and share somethings with us right from the start of the video. Thank you so much!!!
This is the best tutorial series I have ever watched on anything! Really well done
6:24 What we all think of CZcams!
This series is seriously a BIG help, I am a 10 year old game designer, (I have been interested in making games more than playing them) and your tutorials are the best I could find on the internet. Would recommend to anyone starting in unity!
I envy you lol.Wish i had access to this when i was 10 :D
I'm very happy to see you two young people trying to develop games! You are the future! Good luck my friends!
Lol I am 12 and developing tooo xD
xblooified no way you’re ten, you have better grammar than like half of the internet.
13 XD
Even as a CS student, with my head hit all day with OO programming, your vids are nothing like boring. Best chanel.
This guy has real ability to learn others ! The way he explains programming is so cool . I have met lots of teachers, who were not able to transfer the knowledge this effectively :) good work
You have amazing tutorials!! I am currently busy on a game and your basic tutorials like this really help me with it!
I am making a game at school and the teacher is really looking forward to my finished product :D
Post a link to some pictures of it when you are done :D and don't forget to reference Brackeys if you copied any code directly :)
Shane McNeill Alright!!
I will do that :D
@@KineticPixell So what happened to a game?
Continue your videos man, its very helpfull and you're a great teacher ! Nice work Brackeys :D
These are really solid tutorials, mate! I am almost 30 years old and trying to get into game dev again. I screwed around with GameMaker in my teens for a few months and haven't really done anything else since. Cheers!
I don't comment much, but I love this guy's videos. I've tried so many things to learn gaming making. I've done Udemy, Corsera, and a few others. All of them seem to throw you into the wolves den when you start and they give you too much info in a short amount of time, its refreshing to see someone who is taking us steps at a time. One thing I'm glad about is that I just found this channel a while ago, so i have a massive backlog to watch and learn. Thank you so much Brackeys.
lol u still give hearts even after 2 years... thats so cool.... btw ur tutorial is way more easier to understand then others i watch :)
not anymore sadly :( brackeys has helped me a los too
yh he quit :(
I donated to patreon, liked and subscribed! Keep up the hard work!
I was worried I'd have to end up coding something to make the camera follow the player, but I'm happy it was so simple. I'm so glad your channel exists, thanks!
Wow, these are some of the best tutorials I've ever seen on any topic!
So cool! Thanks, Brackeys!
i think this is the only time i've pressed the bell when the youtuber says too
it feels so much easier once you finish all of the trouble shooting and even that is fun! thanks so much for making these tutorials!
Thank you for this series, its so easy to learn from you, I made the game in about 7 hours and remembered everything, Thank you so much!!!!!
6:24 *the first time Brackeys shows emotions.*
tHIS GUY DESERVES THE BEST THIS GUY DERSERVES WAY MORE SUBS.
cAPS LOCK SHIFT?
I'm loving this series, the tutorial are so clear and quick, thanks a lot.
I love these so much, trying a code and finding the problem when it doesn't work is so frustratingly satisfying
I did every single thing in the video in the same way that you did. BUT, it did not work the camera is still rotating with the player...help
**(edit) nevermind I found the problem... I forgot to unparent the camera.**
jaaj i was looking for 30 min and saw your edited comment
thnx
@@sbruins35 Drag it away from whatever you parented it to and place it I anywhere in the hierarchy (were all your other things are)
Edits isn't working so I'm gonna put this here 0:48 is were he Un-parents the camera
Thanks!
directed by :
My notes on this vid so you don't have to rewatch it: Video 4: Camera Follow
Drag and drop camera onto player object. This creates a problem where the camera spins with the player and we must add a script to fix it. We then unparent the camera from the player (Drag camera object back to the list.) and create a script that makes the camera follow the location of the player.
public Transform player; //adds a variable named “player” that tracks their Transform (Location)
This will create a slot in the inspector for the camera. Just drag the player object to that slot.
Then add transform.position = player.position // transform with a lowercase t refers to the location of our current object, aka the object this script is sitting on (the camera) then tells the camera’s position to update to the player’s position.
At this time, the camera is now inside the player object and we want to move it back.
We’re going to go back into the FollowPlayer script and add public Vector3 offset;
Vector3 is just keeping track of the x y and z variables. Set the variables to w/e you want the camera offset to be like Y 1 and Z -5 to move the camera up and back.
Then go back into the code and change
transform.position = Player.position;
to
transform.position = Player.position + offset; //this means your camera’s position is the same as the player’s but combined with the offset.
it says that Transform does not contain a definition for potition :\
@@greyseth2721 try lowercase transform
thank you it helped a lot
These are great! I was learning Python for a while now as I was really scared of C# and here I am actually seeing that C# isn't that hard, plus the satisfaction that the code have real life output. Thanks!
You are the first youtuber what i saw who cuts the crap, has a good tempo and says only the important information. Keep up!
Awesome as always!
I'd reccommend anyone starting with game development to watch Brackey's tutorials.
Your tutorials are some of the best I've ever seen. Worth more then PAYED tutorials.
I am starting programming while still in highschool so that i have experience when looking for a job. This series is really helping me thanks so much!
I am still in middle school and i am starting to learn programming in c# and python not to brag but yeah
how to make the camera moves with the player .
hold the camera and drop it on the player . DONE !
30 second tutorial .
THIS IS WHY I LOVE THIS CHANNEL . . . because of its SIMPLICITY
P.S . I watched the whole video
For anyone that got a compiler error saying that transform (in the line transform.potition = player.position) this is what worked for me:
Create a new public transform (I called it "me") and set that transform object to the camera. Then just change (transform.position = player.position) to (me.position = player.position)
Oh thank you!
Thank you so much; I had this issue and your solution worked!
Clear, concise to the point. What more could I ask for. Loving these.
You are the best unity tutor in the universe! NGL!
To make an automatic offset:
top of class:
*private Vector3 offset*
start method:
*offset = transform.position - player.position;*
update method:
*transform.position = player.position + offset;*
Owez wait what lol
@Achintya Dass shut up
thanks! helped
ps. that is my code
using UnityEngine;
public class camerafollow : MonoBehaviour
{
public Transform player;
public Vector3 offset;
void Start ()
{
offset = transform.position - player.position;
}
void Update ()
{
transform.position = player.position + offset;
}
}
@@kasiaczek0000 Thanks. I was having an error and your code worked!
"Unless you have experience with college level math,"
Me, a person that used to have experience with math and now doesn't; *_casually starts shaking_*
If anyone has the issue in the console where it says something about SystemDebug or UnityEngine.Debug, then change...
"Debug.Log(player.position);"
To
"UnityEngineDebug.Log(player.position);"
PS: You just earned a sub because of this. So many people have made this a lot more complicated then it should be when it comes to using Unity or coding, you are not one of those people. Thanks Brackeys.
Seriously, good job! This makes learning unity so much easier!
I am still in High School, and this really helped me, so i think when we start to do things like this, I will be able to be really good at it. Thanks :)
Bro cam you maybe help me out? The video won't load as if it's been deleted.. I really wanna be able to know how to make the camera work but I can't without this video
@@HazardIg same happens to me, did you find a fix?
Actually, someone else in the comments posted a different video which is for the camera as well: czcams.com/video/MFQhpwc6cKE/video.html
@@GioTeo Not yet no, still trying things out
@@GioTeo found a work around
yeah i call myself a coder
c copy
o off
d brackeys
e tutorials
r :)
@@avinath1 ruining shit for people lmfao
@Sam The Scissor Ok guy named Sam The Scissor...
KadabraX_X no body fucking asked
@@ajayselladurai7018 Ok guy named Ajay Selladurai..
KadabraX_X fuck off wanka
This Series is so good im making my first right now and this is helping me understand how to use Unity! Thanks!
You are a great team! I started from your C# tutorials and now I'm studying Unity by your videos. And this is very fun and inspiring! Thank you!
Hi.
I learnt all i know from brackeys...
I'm a game developer too........
I can help with any question
please ask your questions i can help
i also make game development videos
please support my channel
czcams.com/users/itsPeziTutorials
This doesn't work for me... I followed along with the tutorial and even downloaded the source code and nothing changes; it doesn't even give a first-person view. I really enjoyed your tutorial and hope I can get some help.
EDIT: I used Brackeys Smooth Camera Tutorial and I got it to work.
worked for me in visual studio 2019 & unity 2020 like this
using UnityEngine;
public class followPlayer : MonoBehaviour
{
public Transform playerTransform;
private Vector3 _cameraOffset;
[Range(0.01f, 1.0f)]
public float SmoothFactor = 1f;
void Start()
{
_cameraOffset = transform.position - playerTransform.position;
}
void LateUpdate()
{
Vector3 newPos = playerTransform.position + _cameraOffset;
transform.position = Vector3.Slerp(transform.position, newPos, SmoothFactor);
}
}
man your are a life saviour thankyou so much i was trying to solve this for 2-3 hours
Ur a life saver! Thank u so much!
Thank you!!!
Can you explain the extra stuff that you added?
it still dosent work for me :(
Thank you for these tutorials, I wanted to get into using Unity once but it was very confusing, but now I understand things.
Dude, your tutorials are freaking awesome! For once a tutorial video that's very info-dense and it's easy to follow!
This video isn’t working for some reason, but he has another video of the camera follow
Just search “smooth camera following in unity” and it should show up
offset = transform.position - player.transform.position;
that way it stays the way you made it in the scene editor
Thx bro my player would go flying like crazy if you didnt give me that code
thank god your here. i wouldnt of been able to do the code without you lol!!! thx :D
this is the next day ( or night again) of making this game
1 problem that I had is when I tried to run the script of the camera following the player it started going backwards fast after some thinking I realised that I've accidentally got player follow on the camera and player. Turned it off on player and it worked!
thanks for making me actually want to create games
I don't usually Like and click on notifications, but when I do, it means this person is awesome! Im new to coding so this is just amazing.
every time he says, "to do that we need to add another variable" i feel like im dying inside
brackeys left youtube and now i am sad
@@pangisang513 yes RIP
To the people having problem with follow player script... drag and drop follow script to main camera and set offset accordingly.
Every time I write code, it works, and I understand and learn stuff, I get exponential satisfaction. Now I can move a player with controls and have the camera follow!
THIS IS MY JAM, C# AND UNITY TUTORIAL ALL IN ONE IN A WAY I ACTUALLY UNDERSTAND, THANK YOU KIND SOUL
If ur watching in 2022, does anyone have problem watching the vid it keeps saying An error occurred. Please try again later for me..
i reupload this on my channel
czcams.com/video/-r7o4UcSKSE/video.html
you can check it out and continue!
@Brackeys why does it say something went wrong tap to retry anyone else have this issue
You're a gift, pure and simple
Loving this im away to learn game development at college and this so far is giving me a big headstart
Hi dude, amazing video. I'm following it as I'm writing this. One question I had is that my Visual Studio doesn't seem to have the autocomplete that you have. Specifically for the components used by UnityEngine. I'm not sure how to get it. I looked online and they said restarting both VS and Unity should help, but this did not solve it. Is there something else I need to get? Like a plugin or something? Thanks
You have to download Unity tools via Visual Studio installer. Go to Modify/Individual Components in Visual Studio installer, find Unity tools, tick the box, and complete the download.
I had the same problem. JustTestOnly Haha got it right. You have to install unity tools via Visuall Studio Installer. docs.microsoft.com/en-us/visualstudio/cross-platform/getting-started-with-visual-studio-tools-for-unity?view=vs-2019 is what helped out
Go to Edit>Preferences>External Tools. Choose Visual Studio in the External Script Editor. It should be working fine now
Brackey i followed your player movement script but it keeps saying the parameter name player and offset are duplicates, ive even downloaded your project files and used that one but the problem keeps happening, can you help me?
This is very helpful! I appreciate the details you put out in the video, it was very informative!
wish i found this earlier... so far this is the best explained bite sized chunks, just enough to digest :) Awesome vids
Im having trouble getting the camera angle to shownlike his does in the game view. Any suggestions?
Edit: So I fixed it I went to main camera and open/added another camera and that fixed it
When I saw the title, I wanted to try to do it before watching...
*A N D I T W O R K E D*
wait actually nvm i was doing the game object way ;-;
I'm loving this series.
GOT A UNI PROJECT, AND THIS IS THE BEST WAY TO LEARN UNITY YOU ARE A LEGEND BRO 1000X TIMES BETTER THAN MY LECTURERS
Video 4 is not working. comes up with a video error message
i reupload this on my channel
czcams.com/video/-r7o4UcSKSE/video.html
you can check it out and continue!
Anyone else not able to watch the video due to a playback error? I can watch every video except this one just fine
Same
I remember a game that did parenting with the view. It was a racing game on an Amiga 500. We hooked up four of them and were doing an ancient race game similar to Mario cart. The crazy camera view was a highlight of it actually. It made for some crazy and entertaining crashes.
Just Starting Game Development With Unity.
Thanks For The Help
June 2022, is this video not loading for anyone else?
i reupload this on my channel
czcams.com/video/-r7o4UcSKSE/video.html
you can check it out and continue!
If anyone get error NullReferenceException: Object reference not set to an instance of an object. I try to put this :
player = GameObject.Find("Player").transform;
inside start() function, just change Player with your player name. Now it's works well.
Why is it happening
@@lubie_gielde5076 Because you didn't drag your object that you wanted the camera to follow in the script you just made in unity..
what it means is that the program still didn't know what object to follow..
If you save the script and go to unity and click on the camera.. you will see the script and inside it you will see the name player that you just made public is without any object to follow..
so either drag the player from the samplescenes to the cameras script.
or do as Denny said.
and the camera will start following just fine.
thank you so much for these tutorials. you make it easy to understand
No comment… seriously, I have been watching your tutorials and I AM FINALLY UNDERSTANDING something! Thank you so much bro :D
how is it going bro?