Visit the GitHub page for the most up to date source code: github.com/zigurous/unity-snake-tutorial View the FAQ for answers to common questions: github.com/zigurous/unity-snake-tutorial/wiki
if you combine the code for How do I prevent the snake from turning in on itself? + How can I modify the speed of the snake without changing the fixed timestep? - it seems like that if the snake collides with the food, the ResetState is triggered as its thinking its both Food + Obstacle.
@@quangas prevent the snake from turning in on itself: check key input and direction, do nothing when they are in two reverse direction; modify the speed : mark the frame, and move snake only when (frame% speed == 0 ) ; thinking its both Food + Obstacle : I had the same problem , this was because the bodypart instantiation position is the same as the food, just try to instantiate it somewhere else( eg. down below the platform)
@Zigurous just want to thank you again if you want to test out my game here's the link I just need to do some finishing touches spiderdlh.itch.io/snake
Finally a videographer who has working tutorials and codes cleanly and beautifully! It doesn't just say "control c, control v", it explains things. Thank you very much for the video!
You rock Adum, I appreciate all the help. I wanted to switch from GameMaker to Unity, and the easiest solution I thought was "Well, they taught me how to make Asteroids as my first project for GM, let's look up that and see what translates." And now I'm here going through them all.
Thank you for this! I've been searching for this for quite a while and it just came up with long tutorials, but your tutorial was really clear and not that long.
bro the tutorial was fine perfect ten, but theres smthing else i wanted to point out roaming the comment section for a wall teleportation "add on" i was shook. why tf u so helpful ?
Great tutorials for people just starting out. I love trying to figure out a simple game like this and then when I (inevitably) can't figure it out, seeing how you solve the problem. In this case I had a super convoluted way of having each segment follow the head and then when I saw how you did it, my mind was blown. Thank you!
starting my journey going through these videos, I think its pretty cool to learn about the older games and how they function to really learn about more modern games
Really great tutorial. Straightforward and easy to follow. I'd recommend going into what lists are a little more for beginners as that's actually a more advanced topic for people just starting.
This is a great video, one of the best of its kind, I'd say. Very informative explanations, yet short enough not to get boring. I am pretty much a complete beginner and I have learned so much already. Very nicely done! I thank you for the video and will be definitely going deep into your channel to learn more.
As a 1-year in beginner game developer, I have developed a sense for when a beginner tutorial is good or not and this was definitely just right❤ In that it is very simple to follow, give a good backbone for the project that we can then go on to mess around with, and most of all keeps it clean and simple, I’ve seen people make this harder than it needed to be. Sure there’s more optimized ways but this is just right for someone to learn. Thanks a lot for this❤ subbed🙌🏻
OMG this is Most awesome Tutorial ive seen so far very simple and very clear to follow up and as a beginner i feel i could do it by my self if i study this video Thank you
10/10 Tutorial im new to unity and you actually explained so well! easy to understand and follow along and you dont just tell us what to do you actually show how to do it and what it does
Btw, for any begginer Unity dev out there stumbling on this tutorial, changing the Timestep in the project settings might be fine for a simple prototype like this, but it is a very destructive operation that changes the behaviour of every animation, every other physics interaction, basically changes your whole game. Sometimes that's ok, but if you need a less destructive solution, try setting your "Move" to a method, and then use "InvokeRepeating" to call that method repeatedly, instead of using doing everything in FixedUpdate. Something like this: private void Start(){ InvokeRepeating("Move", 0.2f, 0.2f); } public void Move(){ this.transform.position = new Vector3( this.transform.position.x + direction.x * speed, this.transform.position.y + direction.y * speed, 0f ); } Then, if you need the snake to move faster, you just change the rate at which the repeat calls itself (where it's 0.2f)
Yes you are right. This code should work but the only possible problem is that the snake might not be aligned to a grid, which for some people might not matter at all. In that case, this is a simple easy solution. I also have another implementation of speed without using fixed timestep that ensures the snake still aligns perfectly to a grid for those interested: github.com/zigurous/unity-snake-tutorial/blob/speed-controls/Assets/Scripts/Snake.cs
hey this was awesome. This was my first unity project. Im a software engineer by trade and found this guide to be at exactly the right level of detail. Thank you!
Without a doubt one of the best Unity tutors I have watched. Explanations are easy to understand. Doesn't speed through the scripting assuming we are all on his level. Well done.
OK, this is a pretty cool tutorial. Love the method of moving the segments in reverse order. I'm sure with a little bit of creativity this can be used in any kind of cool stuff when following a target
I`m new to Unity so this was a good introduction to using it practically. I will work through your other Videos in order. A suggestion for a future game something like Galaga would be interesting to see how you would do the aliens diving / following paths then reassemble themselves back in formation. Keep up the good work.
Awesome tutorial! Easy to follow and I made your explanations into little notes for myself in the code. Will definitely do some more of your tutorials!
Thank you so much for this tutorial ! I've made snake twiche thanks to it, it's awsome ! I'm not perfectly fluent in the syntax yet and i find transforms really confusing but thanks to you i really feel like i'm improving, thanks you so much ! you are an awsome person !
Thank you so much for this. I’ve been looking how to make a snake game for a while but every tutorial I’ve tried either doesn’t make sense or doesn’t work. I found a long script that does work but doesn’t explain anything and uses all code and materials for the snake and food and I don’t have a clue how to do that myself. I feel I can learn how to do everything in this tutorial and will be able to make my own snake game after learning what’s on here. I was about to give up on tutorials til I found this and thought I’d give it one last try so glad I did. So much I want to try and expand on now.
at around 41:40 a MUCH simpler way around this is to reload the scene... or disable player movement and bring up a game over canvas and reload the scene if the player clicks the retry button on said canvas
@@darkercore8185 hey so I tried reloading the scene but it is not working. for some reason the snake collides with its body ? I dont know why. and I can't just change the snake head prefab to obstacle. did you find a workaround for that ?
Thanks for the tutorial! I'm just learning how to use unity and this helped a LOT! I have no game dev experience but do have a background of C and JavaScript (fairly basic understanding of JavaScript), so learning the syntax of C# is... well it feels weird haha and this tutorial helped me pick up the syntax!! Plus this is my first ever game made in unity! I got a great mobile game idea but have no idea how to implement it, so your tutorial was my first step in my process of learning unity to a point where I can make my game idea a reality!
Thank you very much for the really perfect explanation, as a beginner i wanted to learn how to go up with Unity, and i saw some good videos tho, but YOURS, like ... it was the best upon. Thanks one more time, i am now able to complete by my own from this point.
Hi Zigurous, loved the tutorial, will be following along with the other ones, really happy to have finished this. If I had to request anything it would be a little-known Atari game called Moon Patrol, don't know if that would get enough views in for it to be worth your time though. Either way, keep doing what your doing, and I'll keep watching :)
36:07 body parts reloacation is the key of this game. I was trying to remake this game for two nights and messed up. The right solution is so simple and elegant.
Just subscribed to your channel! Amazing stuff and you explain everything so well! I have a suggestion: Could you make a video on adding a start menu to the game and maybe other random features of your choice to basically make the Snake game a finished and polished game!
I'll definitely consider adding menus for some of my next tutorials. I tend to leave it out of the video to cut down on the time, but usually I do include it in the source code available on GitHub. For Snake I didn't make any menus, but maybe we can do a follow-up video with new features.
@@Zigurous These are the features I would really appreciate seeing: - Spawn n apples, and the snake has to eat all n apples, and when the snake eats them all, n more spawn - A simple "enemy" snake that runs on ai, and tries to eat the apple before your snake does. Like the enemy snake shouldn't be very fast. And collisions with the enemy snake count as a game over condition - "Invisible apple mode" where the apples become the same colour as the background, and if you eat an invisible apple, you get more points - And I guess a menu screen for choosing two player mode vs single player. In two player mode there are two player controlled snakes with WASD and the arrow keys These are my suggestions :D Thanks for listening!
Great tutorial, I learned a lot! The only thing I would add is something to make sure you cant turn around and run into yourself. I solved this by checking if the direction variable is not the opposite while checking for the inputs. if(Input.GetKeyDown(KeyCode.W) && direction != Vector2.down || Input.GetKeyDown(KeyCode.UpArrow) && direction != Vector2.down) { dir = Vector2.up; } Hope this helps some people!
In food placement i did this: private void RandomizePositionAndSpawnFood() { float x = Random.Range(-23, 23); float y = Random.Range(-11, 11); transform.position = new Vector3(x, y, 0.0f); } I write coords rather than using Box Collider 2D's Bounds and it worked!
Visit the GitHub page for the most up to date source code: github.com/zigurous/unity-snake-tutorial
View the FAQ for answers to common questions: github.com/zigurous/unity-snake-tutorial/wiki
you should pin this!!
if you combine the code for How do I prevent the snake from turning in on itself? + How can I modify the speed of the snake without changing the fixed timestep? - it seems like that if the snake collides with the food, the ResetState is triggered as its thinking its both Food + Obstacle.
@@quangas prevent the snake from turning in on itself: check key input and direction, do nothing when they are in two reverse direction; modify the speed : mark the frame, and move snake only when (frame% speed == 0 ) ; thinking its both Food + Obstacle : I had the same problem , this was because the bodypart instantiation position is the same as the food, just try to instantiate it somewhere else( eg. down below the platform)
Underrated
@@EpicBunty no
How does this guy only have 278 subs? All these tutorials explain everything so well. Next Brackeys, anyone?
*UwU agreed*
@@marin8294 x2
Actually! YEAH!!
Brackeys doesnt explain every line. He is better than Brackeys. Brackeys would have done this one hour tutorial to only 5 minutes.
That's a name I havent heard of in a long time....
Thanks for watching! Audio got out of sync on this one, but I'll fix it for the next one. Need to adjust my capture and export framerates.
how would i make this game for mobile platform? i mean touch inputs
can you plzz make for mobile platform also
@Zigurous just want to thank you again if you want to test out my game here's the link I just need to do some finishing touches
spiderdlh.itch.io/snake
next bracket guy i think
Finally a videographer who has working tutorials and codes cleanly and beautifully! It doesn't just say "control c, control v", it explains things. Thank you very much for the video!
He is a simple man doing simple codes so that we all can understand. God bless this simple man.
Your fluency in english is astounding. I didn't even remark a single time you stuttered or "uhm"'ed, bravo.
How in the world have u only got 237 subs! This man deserves more!
Just finished this tutorial! Also noticed that Tetris was just added. Thank you Zigurous!
You rock Adum, I appreciate all the help. I wanted to switch from GameMaker to Unity, and the easiest solution I thought was "Well, they taught me how to make Asteroids as my first project for GM, let's look up that and see what translates." And now I'm here going through them all.
Thank you for this! I've been searching for this for quite a while and it just came up with long tutorials, but your tutorial was really clear and not that long.
bro the tutorial was fine perfect ten, but theres smthing else i wanted to point out
roaming the comment section for a wall teleportation "add on" i was shook. why tf u so helpful ?
Great tutorials for people just starting out. I love trying to figure out a simple game like this and then when I (inevitably) can't figure it out, seeing how you solve the problem. In this case I had a super convoluted way of having each segment follow the head and then when I saw how you did it, my mind was blown. Thank you!
bro u might be the brackeys i am so thankful for your teachings and keep uploading i know you could one day grow to the size you derseve
starting my journey going through these videos, I think its pretty cool to learn about the older games and how they function to really learn about more modern games
Thank you for making this! :DD I searched a long time for this kind of tutorials! Thanks again! :)
Actually This man is very organized: his channel, github and also his projects, I like this man
Brakeys++
Really great tutorial. Straightforward and easy to follow. I'd recommend going into what lists are a little more for beginners as that's actually a more advanced topic for people just starting.
th-cam.com/video/BgtM6s5i3xA/w-d-xo.html
This is a great video, one of the best of its kind, I'd say. Very informative explanations, yet short enough not to get boring. I am pretty much a complete beginner and I have learned so much already. Very nicely done! I thank you for the video and will be definitely going deep into your channel to learn more.
As a 1-year in beginner game developer, I have developed a sense for when a beginner tutorial is good or not and this was definitely just right❤ In that it is very simple to follow, give a good backbone for the project that we can then go on to mess around with, and most of all keeps it clean and simple, I’ve seen people make this harder than it needed to be. Sure there’s more optimized ways but this is just right for someone to learn. Thanks a lot for this❤ subbed🙌🏻
Thanks man, i really love this video, your playlist will help me a lot, continue doing this
Grettings from Brazil
OMG this is Most awesome Tutorial ive seen so far very simple and very clear to follow up and as a beginner i feel i could do it by my self if i study this video
Thank you
AWESOME! Best game development tutorial series i've ever seen.
Slow enough to understand and fast enough to make me feel smart for getting it xD Great video!
i love you!!!! i had been stuck on something for days and after watching a few mins of this i figured it out!
10/10 Tutorial im new to unity and you actually explained so well! easy to understand and follow along and you dont just tell us what to do you actually show how to do it and what it does
Man you just helped my complete my first ever game!
You explained everything so well with detail and so much care😊
Severely Underrated🥺♥️
Btw, for any begginer Unity dev out there stumbling on this tutorial, changing the Timestep in the project settings might be fine for a simple prototype like this, but it is a very destructive operation that changes the behaviour of every animation, every other physics interaction, basically changes your whole game.
Sometimes that's ok, but if you need a less destructive solution, try setting your "Move" to a method, and then use "InvokeRepeating" to call that method repeatedly, instead of using doing everything in FixedUpdate.
Something like this:
private void Start(){
InvokeRepeating("Move", 0.2f, 0.2f);
}
public void Move(){
this.transform.position = new Vector3(
this.transform.position.x + direction.x * speed,
this.transform.position.y + direction.y * speed,
0f
);
}
Then, if you need the snake to move faster, you just change the rate at which the repeat calls itself (where it's 0.2f)
Yes you are right. This code should work but the only possible problem is that the snake might not be aligned to a grid, which for some people might not matter at all. In that case, this is a simple easy solution. I also have another implementation of speed without using fixed timestep that ensures the snake still aligns perfectly to a grid for those interested: github.com/zigurous/unity-snake-tutorial/blob/speed-controls/Assets/Scripts/Snake.cs
@@Zigurous Hello, this link doesn't exist, can you provide another one please?
hey this was awesome. This was my first unity project.
Im a software engineer by trade and found this guide to be at exactly the right level of detail. Thank you!
Such a fire Tutorial, you gonna be big someday, keep up the great content!
Great tutorial. Very concise and well explained. Thank you!
Without a doubt one of the best Unity tutors I have watched. Explanations are easy to understand. Doesn't speed through the scripting assuming we are all on his level. Well done.
great video! im super amazed of this quality of videos being your first one, keep going and youll make it far! :D
Thank you! This was a very helpful video! Love the music in the background.
One of the best unity toturails channel !
you are the best teacher ever!
OK, this is a pretty cool tutorial. Love the method of moving the segments in reverse order. I'm sure with a little bit of creativity this can be used in any kind of cool stuff when following a target
I was having trouble sleeping, but after watching this video I slept like a baby. thank you so much☺
I am glad to tell you that your snake game tutorial helped me in 2024!
Very clear tutorial and good rhythm, thank you I learn a lot
I`m new to Unity so this was a good introduction to using it practically. I will work through your other Videos in order.
A suggestion for a future game something like Galaga would be interesting to see how you would do the aliens diving / following paths then reassemble themselves back in formation.
Keep up the good work.
Thanks a lot for this tutorial, it has drilled the basics of Unity and C# in my mind.
I kept getting error cs1061. Can you help me? Im at 19:00 and it won’t move the snake
This is lovely. It's got a nice "happy little snakes" vibe that makes me feel chill like Bob Ross.
Thank you for this tutorial, everything is clear and nice explained! Hope to see new videos from you)
This is great!!, i had a lot of fun following this tutorial!, cheers!!
thank you for this lesson! I really rethought things that I couldn't understand before
Awesome video and explanations! Just the right details and all the necessary much needed information! Thanks a lot!
When it come to quality content this guy never dis
Very clear.. Easy to understand and learn.. Great stuff
Thanks for the great vid Adam. Absolute Legend.
Second tutorial following this channel. First successful game and plan to do them all
Realy cool stuff! You are doing great what you do! Awesome!
Thanks a lot for the tutorial, saved my school project.
Thanks a lot for your tutorial. I am looking forward to seeing all of your videos.
Awesome tutorial! Easy to follow and I made your explanations into little notes for myself in the code. Will definitely do some more of your tutorials!
I thought I had a big monitor, but you're on another level...
Really good job on this video, looking forward to checking out all of the other ones
This video was so life changing, keep up the good work
Thank you so much for this tutorial ! I've made snake twiche thanks to it, it's awsome ! I'm not perfectly fluent in the syntax yet and i find transforms really confusing but thanks to you i really feel like i'm improving, thanks you so much ! you are an awsome person !
Thanks for sharing these tutorials, they're really helpful for a begginer's first step!
excellent tutorial, one of the better on internet.
man, your tutorials are the best. Thank you.
Thank you so much for this. I’ve been looking how to make a snake game for a while but every tutorial I’ve tried either doesn’t make sense or doesn’t work. I found a long script that does work but doesn’t explain anything and uses all code and materials for the snake and food and I don’t have a clue how to do that myself. I feel I can learn how to do everything in this tutorial and will be able to make my own snake game after learning what’s on here.
I was about to give up on tutorials til I found this and thought I’d give it one last try so glad I did. So much I want to try and expand on now.
That's awesome to hear! Keep sticking with it and you'll continue to improve you skills.
at around 41:40 a MUCH simpler way around this is to reload the scene... or disable player movement and bring up a game over canvas and reload the scene if the player clicks the retry button on said canvas
just realized this will not work when you run into your body but whatever
but it DOES work if you set the snake prefab to the tag type obstacle :)
@@darkercore8185 hey so I tried reloading the scene but it is not working. for some reason the snake collides with its body ? I dont know why. and I can't just change the snake head prefab to obstacle. did you find a workaround for that ?
@@EpicBunty I haven't used unity in a minute and iirc it worked for me so honestly, sorry i can't help :(
Great tutorial, very clear and well paced
Thanks for the tutorial! I'm just learning how to use unity and this helped a LOT! I have no game dev experience but do have a background of C and JavaScript (fairly basic understanding of JavaScript), so learning the syntax of C# is... well it feels weird haha and this tutorial helped me pick up the syntax!! Plus this is my first ever game made in unity! I got a great mobile game idea but have no idea how to implement it, so your tutorial was my first step in my process of learning unity to a point where I can make my game idea a reality!
Thank you very much for the really perfect explanation, as a beginner i wanted to learn how to go up with Unity, and i saw some good videos tho, but YOURS, like ... it was the best upon. Thanks one more time, i am now able to complete by my own from this point.
good work and thank you so much, Greetings from Egypt
Great tutorial! I want to see more of tutorials like this :D
Very good tutorial!!! Fantastic pace and easy to follow along. Thank you good sir...
I think this guy will go big :)
Hi Zigurous, loved the tutorial, will be following along with the other ones, really happy to have finished this. If I had to request anything it would be a little-known Atari game called Moon Patrol, don't know if that would get enough views in for it to be worth your time though. Either way, keep doing what your doing, and I'll keep watching :)
Thank you very much for this tutorial! It was super easy to understand and very helpful! :D
The great turotial, sir. I understand C# a little, newbie level. I look at your notes and repeat actions, based on my memory.
Thanks so much for this! It was very fast, simple and easy to learn!
Another great tutorial! Thanks!
thank you so much, super simple and great for begginers ! made my first game :D
Thank you for this!
Thanks, this is very nice! I learned a lot from this.
36:07 body parts reloacation is the key of this game. I was trying to remake this game for two nights and messed up. The right solution is so simple and elegant.
you are awesome brooo❤❤❤❤ learned a lot of basics. love from India
OMG, it really worked. Thank you so much!!
Thanks a lot - your video is a Great start to soft soft. I'm onto it !
Just subscribed to your channel! Amazing stuff and you explain everything so well!
I have a suggestion:
Could you make a video on adding a start menu to the game and maybe other random features of your choice to basically make the Snake game a finished and polished game!
I'll definitely consider adding menus for some of my next tutorials. I tend to leave it out of the video to cut down on the time, but usually I do include it in the source code available on GitHub. For Snake I didn't make any menus, but maybe we can do a follow-up video with new features.
@@Zigurous May I suggest a few features to do?
Sure, what would you like to see?
@@Zigurous
These are the features I would really appreciate seeing:
- Spawn n apples, and the snake has to eat all n apples, and when the snake eats them all, n more spawn
- A simple "enemy" snake that runs on ai, and tries to eat the apple before your snake does. Like the enemy snake shouldn't be very fast. And collisions with the enemy snake count as a game over condition
- "Invisible apple mode" where the apples become the same colour as the background, and if you eat an invisible apple, you get more points
- And I guess a menu screen for choosing two player mode vs single player.
In two player mode there are two player controlled snakes with WASD and the arrow keys
These are my suggestions :D Thanks for listening!
Thanks bro
great tutrial i learned alot
Loved your video!
What an amazing tutorial Thank you so much for this i have give you a subscribe and a big thumbs up
video so classy 💯
Dude thank you. Im grateful
completed making the game, was fun thank you :D
You do great work bro. Keep it up bro.❤❤
The legend was born
Great tutorial, I learned a lot! The only thing I would add is something to make sure you cant turn around and run into yourself. I solved this by checking if the direction variable is not the opposite while checking for the inputs.
if(Input.GetKeyDown(KeyCode.W) && direction != Vector2.down || Input.GetKeyDown(KeyCode.UpArrow) && direction != Vector2.down)
{
dir = Vector2.up;
}
Hope this helps some people!
where did you put this in the code would be helpful
Thank you, helps alot!
Thanks bro that was really helpful
Awesome, my very first game ready!
Great tutorial!
Really enjoyable videos. I just subscribed, but have to thank you for your knowledge sharing and (re)creating these pearls. :)
love your video really helps me as a beginner
In food placement i did this:
private void RandomizePositionAndSpawnFood() {
float x = Random.Range(-23, 23);
float y = Random.Range(-11, 11);
transform.position = new Vector3(x, y, 0.0f);
}
I write coords rather than using Box Collider 2D's Bounds and it worked!
nice
Return a random int within [minInclusive..maxExclusive), so Random.Range(-23, 24) and Random.Range(-11, 12);
Nice video🔥🔥❤️❤️👏👏
I want more games to learn please make another 2D games so that i can understand the work of every single codes in game🙏🙏
I have a number of others tutorials already made, and I'll be making more soon! Check out and subscribe to the channel: th-cam.com/users/zigurous
@@Zigurous yes I see all nice game videos 😍👏👏❤️