Endless Runner Level Generator in Unity Tutorial (Spawn Level Parts FOREVER)

🌍 Get my Complete Courses! ✅ unitycodemonkey.com/courses
👍 Learn to make awesome games step-by-step from start to finish.
Let's create a Level Generator to make levels for a Infinite Endless Runner in Unity 2D.
✅ Get the Project files and Utilities at unitycodemonkey.com/video.php...
Endless Runner Level Generator (Difficulty + Highscores) in Unity • Endless Runner Level G...
Simple Jump in Unity 2D
• Simple Jump in Unity 2...
If you have any questions post them in the comments and I'll do my best to answer them.
🔔 Subscribe for more Unity Tutorials / @codemonkeyunity
See you next time!
📍 Support on Patreon / unitycodemonkey
🤖 Join the Community Discord / discord
📦 Grab the Game Bundle at unitycodemonkey.com/gameBundl...
📝 Get the Code Monkey Utilities at unitycodemonkey.com/utils.php
#unitytutorial #unity3d #unity2d
--------------------------------------------------------------------
Hello and welcome, I am your Code Monkey and here you will learn everything about Game Development in Unity 2D using C#.
I've been developing games for several years with 7 published games on Steam and now I'm sharing my knowledge to help you on your own game development journey.
You can see my games at www.endlessloopstudios.com
--------------------------------------------------------------------
- Website: unitycodemonkey.com/
- Twitter: / unitycodemonkey
- Facebook: / unitycodemonkey

Пікірлер: 759

  • @CodeMonkeyUnity
    @CodeMonkeyUnity5 жыл бұрын

    Check the follow up video where we complete our Endless Runner Mini-Game with increasing difficulty and a Highscore Table kzread.info/dash/bejne/mad4taeOf6-teKg.html

  • @sagarrawal5195

    @sagarrawal5195

    4 жыл бұрын

    can anyone please tell me how to make and image as an platform for the player to run im very beginner i only want make an 2d endless runner or a runner game with levels but there are good tutorial out there

  • @gamedevspecialist220

    @gamedevspecialist220

    4 жыл бұрын

    How can I delete the prefabs after it left the screen?

  • @shikkuu8295

    @shikkuu8295

    3 жыл бұрын

    @@gamedevspecialist220 acually im new to unity but you could say destroy after secodnds or you could make a border which is folloing the player and destroyes the platforms then the player also haves a time limitation i dont know if i could help

  • @shikkuu8295

    @shikkuu8295

    3 жыл бұрын

    @@sagarrawal5195 you know now? i made it over a tilemap but you can also just use sprites

  • @MrBucket77

    @MrBucket77

    Жыл бұрын

    How can I make it not infinite but that there is an end?

  • @JamesArndt
    @JamesArndt4 жыл бұрын

    Couple of concerns I would have addressed for beginners. You'd require a way to remove the old tiles after they've left the screen, otherwise this system continues to build up resources over time that would eventually lead to memory errors. Second, this system does not implement a way to reset the player to the world center, so as the player continuously moves away from the origin precision will be lost. After enough time playing the app will either crash or the player will become unstable due to floating point imprecision. I would have addressed these two issues first and foremost for any infinite scrolling system as they are core to the system itself not causing application crashes.

  • @VoidFriend

    @VoidFriend

    4 жыл бұрын

    Thanks u dude, appreciated.

  • @icedwarm69

    @icedwarm69

    3 жыл бұрын

    Yes. Just do a triggered collider that destroys a object if hit

  • @COLDoCLINCHER37

    @COLDoCLINCHER37

    3 жыл бұрын

    Can you explain the origin thing? Okay what if your,re player dosent actually move it just seems like it's moving...

  • @breno8119

    @breno8119

    3 жыл бұрын

    @@COLDoCLINCHER37 He is talking about a re root system I believe: kzread.info/dash/bejne/c6WZqNV9frunZLg.html

  • @charbelboughazale3994

    @charbelboughazale3994

    2 жыл бұрын

    One way to solve it is by creating another script that calculates the difference between the player position, and the Instantiated prefab, then it destroys it after the limit is reached.

  • @CodeMonkeyUnity
    @CodeMonkeyUnity5 жыл бұрын

    Create a Infinite Endless Runner Level using Prefabs to make it very easy to create multiple level parts that get randomly chosen. It would be very simple to take this and create separate lists containing some Easy Level Parts and some Hard ones and just change which list it grabs from the further the Player gets. The Project Files also work as a great starting point if you're interested in making a Endless Runner.

  • @incpwnge

    @incpwnge

    5 жыл бұрын

    Hi. Thanks for such ez for all tutorial =) Is this script applicable for 3D model? The model will run on 2D endless runner. For those who see a part of the player, like a fist, helmet, simply do this; (faced this problem on previous projects) Open the file V_Animation.cs and in the Init() function add these two lines right after "isInit = true;" System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US"); This totally fixes.

  • @sagarrawal5195

    @sagarrawal5195

    4 жыл бұрын

    can anyone please tell me how to make and image as an platform for the player to run im very beginner i only want make an 2d endless runner or a runner game with levels but there are good tutorial out there

  • @user-gs4bv4qj4z

    @user-gs4bv4qj4z

    4 жыл бұрын

    If it would be realy endless moving player and not world around player, can couse any trouble when player will approach any high numbers at X? Can you show some mechanics of world moving or give some tip, for seamless reseting player "at zero"? thx in advance

  • @Hisnameisluca

    @Hisnameisluca

    3 ай бұрын

    you have to add a colider so you can stand on it and depending if you are making a 2D or 3D game you will need a diffrent collider you can find them under component hope it helped@@sagarrawal5195

  • @Salmontres
    @Salmontres Жыл бұрын

    Thank you for another great video! I can't count the number of times I go off to make a new mechanic, and you happen to have the perfect video for it!

  • @rafbanaan
    @rafbanaan5 жыл бұрын

    Awesome! I had some ideas in the past, but I never got around on how to start one of these.

  • @seattlebellevue3355
    @seattlebellevue33554 жыл бұрын

    One of the best tutorials. Taught with such simplicity. Pls make more such tutorials. Thanks.

  • @trevorjkeegan
    @trevorjkeegan3 жыл бұрын

    Awesome tutorial. Trying to go from a brackeys beginners tutorial into unity intermediate 3D endless runner was a bit difficult but I think I can apply this concept in 3 dimensions space.

  • @illia_mikhow
    @illia_mikhow4 жыл бұрын

    Very simple and fluent guide, thank you! Also, if anyone want to optimize application, you can simply add to LevelPart prefabs simple self destroy script: private float secondsToDestroy = 20f; void Start() { StartCoroutine(DestroySelf()); } IEnumerator DestroySelf() { yield return new WaitForSeconds(secondsToDestroy); Destroy(gameObject); } Have a nice day :)

  • @bruhvioli

    @bruhvioli

    4 жыл бұрын

    Great idea! What if i wanted to destroy the level parts with the click of a button?

  • @illia_mikhow

    @illia_mikhow

    4 жыл бұрын

    Watch a video "how to handle button on click event on Unity" If you want to destroy all level parts on scene, I would do it like this: Put a tag on each of levelparts, and made a ClickDestroy script, which firstly saves references to all Level Part gameObjects: var parts = Gameobject.GetComponentsByTag("Levelpart"); And than using foreach loop - delete all objects foreach(var obj in parts) Destroy(obj); And than you should put this in separate function in script, and link it to button on click event. Maybe I am wrong in some places, because I dont have opened Unity in front of me, and I wrote functions from head. Good Luck!

  • @bruhvioli

    @bruhvioli

    4 жыл бұрын

    @@illia_mikhow i did it like this: public void DestroyLevelParts(){ levelParts = GameObject.FindGameObjectsWithTag("levelPart"); for(var i = 0 ; i { Destroy(levelParts[i]); } } but when restarting the game you have to place the lastEndPosition back to the fiorst level part like this: lastEndPosition = startPosition.transform.position;

  • @MrSmoofist

    @MrSmoofist

    3 жыл бұрын

    Thanks! just one thing it destroys the parts before you reach them lol, i did it like this: for (int i = 0; i { Destroy(levelParts[i]); } edit: sorry for missing some extra- i made a new gameobject list to contain all the level part clones, then destroy only the clones in the list

  • @romeo4333

    @romeo4333

    3 жыл бұрын

    @@MrSmoofist i get the error: The name 'levelParts' does not exist in the current context' im a unity noob so this is probably easy to fix but an answer would be nice :)

  • @bramvanwambeke1859
    @bramvanwambeke18595 жыл бұрын

    Great video, I've been trying to get a random level generator working, you really helped me alot thanks.

  • @matthewspencer6669
    @matthewspencer66695 жыл бұрын

    Great tutorial. I'd really love some more ECS tutorials, specifically showcasing more complex areas like instantiating complex hierarchy objects from jobs and setting data on the child nodes. Maybe some unity physics stuff too.

  • @hlimajunior
    @hlimajunior3 жыл бұрын

    Amazing, man! That´s this I´ve been looking for! Thanxs!

  • @mono-pg9wm
    @mono-pg9wm4 жыл бұрын

    It was very helpful. Thank you!

  • @CasperA
    @CasperA5 жыл бұрын

    Please do more randomly generated stuff!

  • @lingais
    @lingais3 жыл бұрын

    for those who had problems with Player and GetPosition as i did (for hours, because im new), here's hw i fixed it, hope it helps! For player error, create a script called Player with this code: using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour { public Vector3 GetPosition() { return transform.position; } } attach that script to the player. For GetPosition error, add this code to your LevelGenerator script from the video: public Vector3 GetPosition() { return transform.position; } Many thanks to Jaristos Smith from deep in this video comments and Code Monkey for simplifying the solution for a newbie in one of the comments!

  • @krisery8907

    @krisery8907

    3 жыл бұрын

    I solved it like this: First I changed the SerializeField to a GameObject and not Player: [SerializeField] private GameObject player; And after that just simply use the transform.position function: if(Vector3.Distance(player.transform.position, lastEndPosition) < PLAYER_DISTANCE_SPAWN_LEVEL_PART) ...

  • @GrimmjowJxMimiru

    @GrimmjowJxMimiru

    3 жыл бұрын

    @@krisery8907 Thanks man that works! One more question for you and anyone else. I get my platforms spawn just as i set the initial ones like 3 or 5. But when my character comes to the end of the last platform which was spawn at the start of the game, no new one is spawned. It seems there is an error with the update function to check for the position or for the new spawning. Hope someone has an info for it.

  • @krisery8907

    @krisery8907

    3 жыл бұрын

    ​@@GrimmjowJxMimiru Check if the Platform spawns in the SceneView when you run the game. If yes then make sure that all platforms that spawns are set to 0 in the z Position.

  • @GrimmjowJxMimiru

    @GrimmjowJxMimiru

    3 жыл бұрын

    @@krisery8907 In the Scene View there is also nothing generated. I just cant find the issue. But thanks for the reply, i will need to further check this.

  • @christinerichard4198

    @christinerichard4198

    3 жыл бұрын

    Please guys help me support this new Endless Runner, im sure you'll love it and it'll really help the devs out play.google.com/store/apps/details?id=com.ObinnaStudios.TheCollectors

  • @louislemur
    @louislemur4 жыл бұрын

    Tutorial really helped thanks a lot!

  • @zsirothehero4330
    @zsirothehero43304 жыл бұрын

    Nicely done!

  • @RobertBojor
    @RobertBojor5 жыл бұрын

    Haha, if this isn't the internet guessing what I'm working on, I don't know what it is. I was tinkering on a pixel art mini-game and wanted to generate the levels randomly :) Keep up the good work!

  • @martimking1craft

    @martimking1craft

    5 жыл бұрын

    google is watching you I was thinking that everyone already knew

  • @NawabKhan-vq5de
    @NawabKhan-vq5de5 жыл бұрын

    it was amazing keep it forward sir please

  • @NotTolik708
    @NotTolik7082 жыл бұрын

    thank you so much helped me a lot for my three dimensional project

  • @alexkhazov7264
    @alexkhazov72644 жыл бұрын

    Great video and technique! I do see one possible way to make it even better, and that's by adding a cleanup for the parts that are far behind the player, otherwise, after playing for a while, unity would have to process hundreds or even thousands of objects) Would be interesting to see this same mechanic done in ECS!

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Yup the clean up would indeed be a necessary addition in order to use this in a proper game

  • @siddisking

    @siddisking

    4 жыл бұрын

    I was thinking the same thing and wondering if the creator would mention this... B/w how would one do the cleanup for the platforms and objects which are no longer in the camera view?

  • @alexkhazov7264

    @alexkhazov7264

    4 жыл бұрын

    @@siddisking The simplest solution would be to use the OnBecameInvisible callback, and destroy the gameobject - docs.unity3d.com/ScriptReference/MonoBehaviour.OnBecameInvisible.html Note the small comment they put at the end - this callback also happens when the scene view camera stops seeing the object. So, when the editor scene view camera cannot see the object, it will be destroyed. I would probably only include this function in a built version using #if !UNITY_EDITOR #if !UNITY_EDITOR private void OnBecameInvisible() { Destroy(gameObject); } #endif

  • @KuariThunderclaw
    @KuariThunderclaw4 жыл бұрын

    Great video and definitely appears to have some relevance beyond endless levels but a question comes to mind as I look this over. Don't you eventually get an overflow of resources if for whatever reason a player manages to go on long enough? Say there was a reason one needed to optimize things? I'm assuming you'd just destroy all the level objects that the player is past at the same time as loading the new ones in?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Yup exactly, if you were to implement this in a complete game you would definitely clean up the old platforms. Just cycle through the list and do a simple distance check, if too far, destroy it

  • @boomboom3794
    @boomboom37944 жыл бұрын

    Videos look really interesting, is there a way to see all of these tutorials in one playlist, from beginning to end?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    For this one I just did one more with increasing Difficulty and Highscores kzread.info/dash/bejne/mad4taeOf6-teKg.html And I have done other videos on Simple Jump and Ground Check

  • @s1m1ng7on
    @s1m1ng7on Жыл бұрын

    Great tutorial as always! Wondering how I could do the same but with a group of tiles instead

  • @CSteph_

    @CSteph_

    9 ай бұрын

    How?

  • @RhodeynRusty

    @RhodeynRusty

    6 ай бұрын

    Make sure the parent object your Level Part belongs to has a Grid component on it! Otherwise you'll only save one single tile to the prefab.

  • @OmeedNOuhadi
    @OmeedNOuhadi2 жыл бұрын

    Awesome tutorial!!!

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    Thanks!

  • @baroianandrei7883
    @baroianandrei78834 жыл бұрын

    Thanks you so much, it gave my game a purpose

  • @shubhameditz1683
    @shubhameditz16832 жыл бұрын

    Really Helped Me

  • @vijayanand2783
    @vijayanand27832 жыл бұрын

    Nice Tutorial

  • @8978martin
    @8978martin5 жыл бұрын

    I love this channel you can teach us in this type of game to make an ia that will escape from us and that the coins will give us more speed to be able to catch the ia you could use the spiderman who is trying to catch a thief obstacles make us lose speed and if the thief reaches a goal before we catch him we lose

  • @qtheking5915

    @qtheking5915

    4 жыл бұрын

    AI?

  • @FreedivingTrainer
    @FreedivingTrainer4 жыл бұрын

    Thanks for video. What about clear memory by removing parts which user run from?

  • @faraday3833
    @faraday38334 жыл бұрын

    great tut!

  • @danielmakac3686
    @danielmakac36865 жыл бұрын

    Hey, CodeMongkey Awesome Tutorial! I really love it! Am, Can you make a tutorial video about making a grappling hook system in unity2D. that would be awesome! there not many tutorials about it.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    5 жыл бұрын

    Yes a grappling hook is definitely something I have on my list, not sure when though.

  • @danielmakac3686

    @danielmakac3686

    5 жыл бұрын

    @@CodeMonkeyUnity Thank you so much.

  • @soma_donat

    @soma_donat

    4 жыл бұрын

    I would like to see that in 2D too :) there are no good tutorials of that

  • @raptorswire7212
    @raptorswire72122 жыл бұрын

    great beginner tutorial, however you should at least mention which parts are actually inefficient to use and how to optimize them (object pooling, object.Find killing performance etc...)

  • @ahmedthebest
    @ahmedthebest5 жыл бұрын

    Can you expand this system more, It still need some tweaks like You should get rid of spowne level parts Can you show us How to use This system To generate A top down Road For example

  • @christinerichard4198
    @christinerichard41983 жыл бұрын

    My friend recently finished an endless runner called The Collectors and he would really like some support. Ive downloaded the game and it's pretty fun

  • @craftercis

    @craftercis

    3 жыл бұрын

    I played the game ;). It looks fun and the controls are fine. Only - point is the UI. Its to busy on the screen.

  • @christinerichard4198

    @christinerichard4198

    3 жыл бұрын

    @@craftercis wow..Thank you so much, I'll be sure to tell him

  • @christinerichard4198

    @christinerichard4198

    3 жыл бұрын

    You can send him some feedback, I'm sure he'll appreciate it ☺

  • @josedeolio8464
    @josedeolio84644 жыл бұрын

    Nice Tutorials really helps, I have question I have added all the elements and characters and all the scripts needed. I added the background last but now it seems to be covering everything I did. I did it as a new Gameobject and added everything there it has it's own parallax script attached. any way I can get it behind the character? Thanks!!!

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    If you're working in 2D check the SpriteRenderer Sorting Order and Sorting Layer

  • @romeo4333
    @romeo43333 жыл бұрын

    Hey, this tutorial helped me a lot, but I ran into 1 problem: The generation stops at a certain point depending on this number: private const float PLAYER_DISTANCE_SPAWN_LEVEL_PART = 250f; I haven't seen anyone got this problem too so I hope it is just an easy fix. Help would be really appreciated!

  • @brunosoares6717

    @brunosoares6717

    2 жыл бұрын

    i have the same problem, and dont find the solution yet EDIT** i find one solution that works for me, in my virtual camera who controls the main camera i have set the camera distance to 20, so i just set it to a higher number and works =)

  • @doctorpizza8518

    @doctorpizza8518

    11 ай бұрын

    this happens because your level parts / end positions have a different z value from zero, so you don't notice it but they get further away from player, moving along the z axis until they are so far away the distance condition stays false. to fix, set all your level parts and end positions with z = 0

  • @PixelGeekMaster
    @PixelGeekMaster5 жыл бұрын

    Thanks ! ! ;)

  • @meistergong8759
    @meistergong87594 жыл бұрын

    [serializefield] private Player player; doesn't work. Can you help me pls? Error: The type or namespace name 'Player' could not be found (are you missing a using directive or an assembly reference?)

  • @kairodger238

    @kairodger238

    3 жыл бұрын

    I have the same problem

  • @peterwettenburn3397

    @peterwettenburn3397

    3 жыл бұрын

    I have the same problem too!

  • @jonuko9678

    @jonuko9678

    3 жыл бұрын

    I have it too

  • @nhlanganisotshabangu3774

    @nhlanganisotshabangu3774

    3 жыл бұрын

    @@jonuko9678 If you still need help w this, replace Player w the name of your player movement script

  • @nhlanganisotshabangu3774

    @nhlanganisotshabangu3774

    3 жыл бұрын

    If you still need help w this, replace Player w the name of your player movement script

  • @TheBrickBuilderYT
    @TheBrickBuilderYT Жыл бұрын

    Hey anyone and Code Monkey i have the problem, that the my LevelPart_1 generates mostly in but also under the start platform. This happend when i set the Endposition to the end of the object. if i put the endposition object in the air it generates fine.

  • @butcherbio
    @butcherbio2 жыл бұрын

    I'm new to unity and was wondering if it is possible to do the same kind of generation, but with a tile map? Because I'm kinda in the void right now.

  • @knowledgeseeker8735
    @knowledgeseeker8735Ай бұрын

    If you're having a problem with making the origin of the levelpart different from the child of it then add a new object and remove the sprite renderer (after giving it a random image) then move your real part and adjust the invisible part to make the levelpart origin different.

  • @Unexplained65
    @Unexplained654 жыл бұрын

    I was hoping you would have some kind of way to dump the old prefabs after they were off screen for too long but i will be poking around at how to do that one myself

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Just a simple Distance check would work, cycle through all the level parts and do if (Vector3.Distance(levelPartPosition, playerPosition) > distanceToDestroy) Destroy(levelPart);

  • @TheCyborgCast
    @TheCyborgCast4 жыл бұрын

    With the private Player player; part gets me confused on what 'Player' is that the player movement script?

  • @klareks542

    @klareks542

    3 жыл бұрын

    I have the same problem,I dont know how to fix it.

  • @BigFrogOfWar

    @BigFrogOfWar

    3 жыл бұрын

    i have it also :(

  • @solecito69
    @solecito693 жыл бұрын

    No entiendo por qué la gente se queja por este aporte, a mi parece está muy bien implementado, solo basta con poner algo para que se destruya automáticamente para que el rendimiento no afecte. Y eso que les da GRATIS, se quejan. Además tengan en cuenta que la manera en que se instancia los objetos es a razón de X e Y, si la posición de x = 0, todos los bloques irán perfectamente en vertical y viceversa. Solo deben checar cómo funciona esto, y funciona bien.

  • @aleksp8768
    @aleksp87683 жыл бұрын

    how can i do this if the platforms are made from a tilemap?

  • @Charlie-ei4wh
    @Charlie-ei4wh4 жыл бұрын

    it says that there is an error when i type in the direction for the obstacles to spawn?

  • @at930pmgames
    @at930pmgames3 жыл бұрын

    And if the player dies or want to play again, it will respawn different level parts so every time someone plays, it will be a different map? Whats the best way to build a platform game considering optimization?

  • @mariorolli4309
    @mariorolli43093 жыл бұрын

    I have the problem, that the Endless Runner isn't Endless. For one reason, I don't know why, the minium-distance between the Player and the Last EndPosition grows. And at one Point the Spawn function stops to Spawn new Platforms. Can anyone help?

  • @MinecraftTVGameplay
    @MinecraftTVGameplay5 жыл бұрын

    Hi Code Monkey!Great tutorial!But i have to ask you,can you make a tutorial about making a random generated map where you jump through holes like in a helix jump but in 2d?Thank in advice.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    5 жыл бұрын

    Like Super Hexagon? That is indeed a relatively simple game that I'd like to cover some day.

  • @MinecraftTVGameplay

    @MinecraftTVGameplay

    5 жыл бұрын

    @@CodeMonkeyUnity Wow,such a amazing game,sure,you can make a tut about that.

  • @StockMarket_FinanceEducation
    @StockMarket_FinanceEducation2 жыл бұрын

    I have a problem with the Endposition because the distance between levelpartstart and levelpart_1 is too far away for the Player Pls help

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    What problem? EndPosition is where the next level part will be spawned.

  • @StockMarket_FinanceEducation

    @StockMarket_FinanceEducation

    2 жыл бұрын

    @@CodeMonkeyUnity yeah that is right but when i start the game the distance between levelpartstart and levelpart1 is very far so have you an idea to fix this problem

  • @kagigreenscreen
    @kagigreenscreen5 жыл бұрын

    hi nice tutorial . i got the package and every time i try to add the package it crashes unity just when it gets to 'small assets ' Please help with this Thanks

  • @knowledgeseeker8735
    @knowledgeseeker873520 күн бұрын

    For some of you out there, you might be stuck on the first step after instantiating. When you go to fill out the serialize field, drag the prefab from the project tab, NOT the hierarchy. This makes sure when you delete it, the Serialize Field is still filled because it's not looking for it in the hierarchy, but instead in the Project Tab

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    19 күн бұрын

    Yeah always make sure you use prefab references from the project files and not the scene, otherwise you will get some strange errors if the scene object is destroyed

  • @knowledgeseeker8735

    @knowledgeseeker8735

    15 күн бұрын

    @@CodeMonkeyUnity Yoooo ur still active on this vid?

  • @fheus2439
    @fheus24394 жыл бұрын

    I have a problem: when i want to generate my Level, either I can make an infinite backgrond, which i saw in another tutorial OR i make the camera stick onto my character. Is there a way to have a looping Background Image AND a to-the-character-sticking camera?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    You just need to apply the same logic used to spawn platforms to spawn the background. As the player moves a lot in one direction, spawn another tile of the background.

  • @fheus2439

    @fheus2439

    4 жыл бұрын

    @@CodeMonkeyUnity okay, that worked.Thank you very much!

  • @nantohola4427
    @nantohola44273 жыл бұрын

    I have two questions, Should I always use Quaternion.identity everytime I instatiate something? What is the actual function of Quaternion and the identity used on it, I use on instinct and never truly understood if there are more applications for it.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    Quaternions are used for defining rotation, the identity matrix simply means no rotation which is usually what you want when working with 2D objects

  • @synthwave_4144
    @synthwave_41444 жыл бұрын

    The type or namespace name 'Player' could not be found (are you missing a using directive or an assembly reference? What is happening?

  • @gamingstudio482

    @gamingstudio482

    4 жыл бұрын

    I think....you...mm...you should use.... i dont know i dont have Unity YET

  • @SADIAPOM

    @SADIAPOM

    4 жыл бұрын

    Hello, in case you still haven't found the answer, I fixed this by making it into a private Transform player and change it to player.position instead of player.GetPosition - Hope this helps

  • @modakdid

    @modakdid

    3 жыл бұрын

    @@SADIAPOM When I do that I get the non invocable member Transform.position cannot be used like a method

  • @tobi6758

    @tobi6758

    3 жыл бұрын

    @@modakdid me too

  • @mohammadshahir80

    @mohammadshahir80

    3 жыл бұрын

    @@SADIAPOM thanks a lot man! Had the same problem.

  • @sagarrawal5195
    @sagarrawal51954 жыл бұрын

    can anyone please tell me how to make and image as an platform for the player to run im very beginner i only want make an 2d endless runner or a runner game with levels but there are good tutorial out there

  • @andryfiderana4767
    @andryfiderana47672 жыл бұрын

    One pretty big concern on this video is the approach of infinite runner , usually you'll want to avoid moving across the world, instead moving the world towards you. Otherwise you'll run into distance issues

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    That is only an issue if you move an insane amount, so in this case you'd have to player the game non-stop without losing for several days before you start to get float imprecision.

  • @andryfiderana4767

    @andryfiderana4767

    2 жыл бұрын

    @@CodeMonkeyUnity Yes but only if your game's speed is like this, but its kinda limited, and goes against the concept of "infinite runner".I think most of infinite runner games are more fast paced , with increasing speed over time. So i would still strongy not recommend this kind of approach in any case

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    ​@@andryfiderana4767 As always you need to make your systems suitable for whatever design you're trying to create, so if your game involves hyper speed then yes you would need a different approach. But keep in mind floats only start losing precision at insanely high values (higher than trillions) so even if your character runs super fast and your runs last for hours it's highly unlikely you will reach that problem.

  • @blaaablooo5233
    @blaaablooo52334 жыл бұрын

    if u have a lot of players so your Player variable needs to be an array or list so if u tried to access the setters and getters u cant so my question is if I have many players so instead of refrence it like u did from th eeditor I need to findgameobject of that type(player) In code or there is some thing else I can do I am a beginner thanks and sorry for my bad English

  • @Arab_GameDev
    @Arab_GameDev3 жыл бұрын

    thank you

  • @vasya123456777
    @vasya1234567775 жыл бұрын

    Hello! Can u make video about some kind of pure ECS input system. Thx

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    5 жыл бұрын

    Yes a simple character controller in ECS is something I'd like to cover, shouldn't be too difficult, just make a ComponentSystem to grab the Input and update a Component

  • @CodeMonkeyUnity
    @CodeMonkeyUnity5 жыл бұрын

    🤖Join the Community Discord discord.gg/eHjUVrm

  • @Kogsworth
    @Kogsworth4 жыл бұрын

    Will you run into a problem where your position is too far from 0,0 at some point? Like the numbers will be too big for the CPU to handle?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    The float.MaxValue is a massive amount so it's extremely unlikely unless for some reason your characters are 10000 units wide.

  • @hugabuga-il6125
    @hugabuga-il61254 жыл бұрын

    Thanks💓💓

  • @oystudios3052
    @oystudios30524 жыл бұрын

    Hello, I have a question, I followed to 8:25 but when i tried the code you typed before that it gave an error: NullReferenceException: Object reference is not set to an instance of an object I am brand new to unity in fact this is the first thing i am making and wanted to have this in the game but i know nothing of c# en am still trying to learn it if you could help i would really appreciate it. Here is my code: using System.Collections; using System.Collections.Generic; using UnityEngine; public class levelGenerator : MonoBehaviour { [SerializeField] private Transform levelPart_Start; [SerializeField] private Transform levelPart_1; private void Awake() { Transform lastLevelPartTransform; lastLevelPartTransform = SpawnLevelPart(levelPart_Start.Find("EndPosition").position); lastLevelPartTransform = SpawnLevelPart(lastLevelPartTransform.Find("EndPosition").position); lastLevelPartTransform = SpawnLevelPart(lastLevelPartTransform.Find("EndPosition").position); lastLevelPartTransform = SpawnLevelPart(lastLevelPartTransform.Find("EndPosition").position); lastLevelPartTransform = SpawnLevelPart(lastLevelPartTransform.Find("EndPosition").position); lastLevelPartTransform = SpawnLevelPart(lastLevelPartTransform.Find("EndPosition").position); } private Transform SpawnLevelPart(Vector3 spawnPosition) { Transform levelPartTransform = Instantiate(levelPart_1, spawnPosition, Quaternion.identity); return levelPartTransform; } }

  • @rudders8054

    @rudders8054

    4 жыл бұрын

    same. you find a fix?

  • @oystudios3052

    @oystudios3052

    4 жыл бұрын

    @@rudders8054 yes, i am a bit more familliar with unity now. I don't know if this is what i did wrong because this was 2 months ago. What i think you need to do is check if you assigned your levelpartstart to a gameobject in the scene or a prefab, if you have it selected as a prefab then the solution is to already have the levelpartstart in game or just use an empty game object to then put it in the serializefield of the editor and change the way the first part spawns just to that point (the transform of the gameobject) What this error actually means is that the reference you made (probably a GameObject variable) is empty, so it couldn't get that GameObject. Alternatively you can make the game simpler by using a linear approach with no height differences, blackthornprod has a tutorial for this wich I ended up using instead of this one: kzread.info/dash/bejne/Z4Fr2LqYqpmoaaw.html If you do want to go further with this one you can check the unity docs and threads about this error I will link the unity docs page here: docs.unity3d.com/Manual/NullReferenceException.html

  • @rudders8054

    @rudders8054

    4 жыл бұрын

    @@oystudios3052 the serializefield starting point fixed it. Thankyou SO much. i'll check the other tutorial too

  • @oystudios3052

    @oystudios3052

    4 жыл бұрын

    @@rudders8054 no problem, happy I could help :)

  • @tizianaminerva2470

    @tizianaminerva2470

    4 жыл бұрын

    @@oystudios3052 could you explain it more?

  • @Mammadexe
    @Mammadexe3 жыл бұрын

    hi i want to destroy the instantiated objects after i pass them but when i use Destroy(levelPart) it says i couldnt destroy transforms

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    You need to destroy the game object Destroy(transform.gameObject);

  • @ThinkForward0
    @ThinkForward04 жыл бұрын

    mine is 3D HyberCasual Game , when i did the spawning with the same prefab ( which has 2 obstacles in it ) it kept producing 1 obstacle then 2 obstacles instead of the 2 from the prefab , can some one please help

  • @NawabKhan-vq5de
    @NawabKhan-vq5de5 жыл бұрын

    sir please make a 3d shuter game series using ufps please....

  • @zinedinemaylano2308
    @zinedinemaylano230827 күн бұрын

    hello, i have a question, can u tell me how to implement the GENETIC ALGORITHM from Procedural Content Generation to game like this?

  • @minedeath_gt
    @minedeath_gt4 жыл бұрын

    Hi can you help me with a problem?, when i run the code it says the namespace Player could not be found.

  • @jaristossmith9125

    @jaristossmith9125

    4 жыл бұрын

    I believe I ran into the same problem. I created a separate script named "Player" and inside I wrote this: using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour { public Vector3 GetPosition() { return transform.position; } } I then attached this script both to the object "LevelGenerator" and the actual player object as their components.

  • @wethescooters5119

    @wethescooters5119

    4 жыл бұрын

    @@jaristossmith9125 yay thanks

  • @jaristossmith9125

    @jaristossmith9125

    4 жыл бұрын

    @@wethescooters5119 No problem :)

  • @uditwarikoo266

    @uditwarikoo266

    4 жыл бұрын

    @@jaristossmith9125 thanksssssss... I've been looking for a solution for so long!!!!

  • @christinerichard4198

    @christinerichard4198

    3 жыл бұрын

    Please guys help me support this new Endless Runner, im sure you'll love it and it'll really help the devs out play.google.com/store/apps/details?id=com.ObinnaStudios.TheCollectors

  • @shimoncohen1624
    @shimoncohen16242 жыл бұрын

    Nice Vid! how can I generate this horizontal?

  • @xoduk
    @xoduk2 жыл бұрын

    I know this was forever ago, but how would you go about creating biomes/worlds. Not just have random parts be different, like pick from a list 0, 1, 2... and if its biome 0 pick from this arrayList to spawn parts, else if biome 1 use this arrayList to spawn parts. I feel like I could figure it out but wanted to make sure I don't do it wrong and I don't see any tutorials for it.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    Have multiple lists for each different biome. Then maybe you select the biome based on distance, every 100 units the player moves you randomly pick the next biome. Then pick the next parts from the selected biome list

  • @ltcSpitfire
    @ltcSpitfire4 жыл бұрын

    When I try to instantiate LevelPart_1, even though the EndPosition is at the same height as the LevelPart_Start, the cloned prefabs spawn lower than each other over time. If I raise the EndPosition on the LevelPart_1 compared to LevelPart_Start, the first clone is lower then it begins to climb. I'm totally lost as to why.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Check the origin of your level parts, add some Debug.Logs to verify that the EndPosition is what it should be

  • @ltcSpitfire

    @ltcSpitfire

    4 жыл бұрын

    @@CodeMonkeyUnity Yeah it was the prefabs origin, it had moved.. sleeping on it helped see it haha plus my placeholder sprites aren't the best to represent a flat platform. Thank you.

  • @ltcSpitfire

    @ltcSpitfire

    4 жыл бұрын

    @@CodeMonkeyUnity How would I destroy the start and other prefabs after they have been used and are out of the camera view?

  • @christinerichard4198

    @christinerichard4198

    3 жыл бұрын

    Please guys help me support this new Endless Runner, im sure you'll love it and it'll really help the devs out play.google.com/store/apps/details?id=com.ObinnaStudios.TheCollectors

  • @Arab_GameDev
    @Arab_GameDev3 жыл бұрын

    anyown have the same problem : refrence Player , .... you can go with "private Transform player" &&&& in the GetPosition you can write "player.transform.position" it Works . this's all the problem i VS in this tuto

  • @kidimaus1

    @kidimaus1

    2 жыл бұрын

    pmg thank you so much. when i did the player.GetPosition it didnt work but somehow it did in the video. i went crazy and you reallly really helped

  • @LostDeception
    @LostDeception4 жыл бұрын

    Hm when getting the level start position using ("EndPosition").position it makes my object sprite not render. Using the new Vector3(x,y) seems to work fine.. i am a tad confused lol

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Check the Z position, if you have it as a non-zero value eventually the platforms will start being spawned behind the camera.

  • @artsurock
    @artsurock2 жыл бұрын

    Hi! I have a problem, i'm doing a 3d endless runner and i used the same code. For first 5 platforms it works nice but after platforms start to appeare in the right places, however they are invisible. I checked layers but these platforms have same layer with first five platforms, other components same too, i wrote similar code but with other approach and it works simmilar, first five platform are visible and other not, please help me if you know what i 'm doing wrong

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    Check the Z position, everything should be on Z = 0 If your endPoint is on a different Z then every new platform will be further and further away from 0 until its behind the camera and you can't see it

  • @SociopathDev
    @SociopathDev5 жыл бұрын

    Hey, newbie question when to use SerializeField? thanks for your tutorials btw!

  • @mehmedcavas3069

    @mehmedcavas3069

    5 жыл бұрын

    Its for variables which are private. You can see public variables in the unity inspector but not private ones. However, when you add [SerializeField], your variable is still private but you can access it from the unity inspector. Try your self to see your variable in the inspector with serializefield and without :)

  • @DexterDLopez

    @DexterDLopez

    5 жыл бұрын

    You use SerializeField on a private variable when you want to see it and modify it in the inspector while also keeping it protected from other scripts from accidently using it

  • @SociopathDev

    @SociopathDev

    5 жыл бұрын

    Thanks I understand it now, and another newbie question, what about serializable?

  • @DexterDLopez

    @DexterDLopez

    5 жыл бұрын

    @@SociopathDev I'm not 100%, but I think it makes a script that's not attached to an object accessible via script. Try looking the term up in Documentation on Unity's site

  • @mehmedcavas3069

    @mehmedcavas3069

    5 жыл бұрын

    @@SociopathDev lets say you created a normal class which is not monobehavior. When u create an object of this class in another monobehavior u cant see it event when it is public. you can see it when u write System.Serializable over the class. If want i can give an example :)

  • @alexv9607
    @alexv96073 жыл бұрын

    Great tutorial and can you make a 3d version of a endless runner game?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    The logic is all the same, just use 3D Meshes instead of flat quads

  • @anubis8450

    @anubis8450

    3 жыл бұрын

    @@CodeMonkeyUnity [SerializeField] private Player player; doesn't work. Error: The type or namespace name 'Player' could not be found (are you missing a using directive or an assembly reference?) What's going on?

  • @GreyRakun
    @GreyRakun4 жыл бұрын

    Is there a way to do it without finds?

  • @AzaiKang
    @AzaiKang Жыл бұрын

    1. The previous generated platforms are now de-spawned, this will cause a lot of errors. 2. The player keeps moving forward. This will cause problems when playing long enough. 3. Unoptimized code.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    Жыл бұрын

    This is a basic tutorial, it's not supposed to be final production ready code, so yes it is unoptimized and yes it doesn't have some features like despawning

  • @theUnfrench
    @theUnfrench11 ай бұрын

    I wanna preface this by saying i haven't touched Unity in a good few months. Currently having a small problem with the "private Player player" biy here. I have a Player game object, and a PlayerMover script. When I try "private Player player", it gives the red squiggly line. "private PlayerMover player" doesn't give the squiggly, but then it doesnt give the option for "GetPosition". I tried to grab the rigidbody in the PlayerMover script and get its position, but that either didn't work, or I didn't do it right. Any correction you can provide would be pretty great rad 🤙

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    11 ай бұрын

    If you don't have any class named exactly Player then it gives an error. For a GetPosition() function you probably just want to get the transform.position

  • @hanzWtc
    @hanzWtc4 жыл бұрын

    I'm going to make a millionaire game thanks to this tutorial!! :D

  • @ivankuhn1921

    @ivankuhn1921

    3 жыл бұрын

    Seiryu how is it going bro?

  • @fare5674

    @fare5674

    3 жыл бұрын

    Is tge game finished

  • @EricSyz

    @EricSyz

    3 жыл бұрын

    Hopefully u'll be able to finish it

  • @jayjohnson4143
    @jayjohnson4143 Жыл бұрын

    Where should I implement the 'Player' class? I've tried importing it into the levelGenerator script and it doesn't seem like I have one?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    Жыл бұрын

    Wherever you want, it can be anywhere in your code base, you can use whatever player controller you want, the Level Generator doesn't care

  • @KvVortex
    @KvVortex4 жыл бұрын

    What did you do the levelpart_1 at @4:03 ?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Just deleted it since it gets instantiated in run-time

  • @anshulsingh8326
    @anshulsingh8326 Жыл бұрын

    Sometimes player just get little inside the ground collider after falling from high places. How to fix it? It doesn't happen always and it happens randomly at different places.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    Жыл бұрын

    Change the rigidbody collision detection to Continuous instead of Discrete

  • @ImusingX
    @ImusingX4 жыл бұрын

    omg i god a CODE MONKEY AD while WATCHING a codemonkey VIDEO How rare is this

  • @Dxstin
    @Dxstin3 жыл бұрын

    How do I get my Tilemap in Prefabs?

  • @siddisking
    @siddisking4 жыл бұрын

    Why are you using multiple types of cases in a single file? I am new to c# so don't know much about using snake, pascal and camel case together. If there a reason for doing this?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    I use PascalCase for class and function names and camelCase for variables. Only use Snake case when I feel like I need to add more "grouping" to a some name so very rarely.

  • @gameofcharging
    @gameofcharging3 жыл бұрын

    Hey, I have a question. What's the difference between Awake and Start method?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    Awake(); runs before Start();

  • @harikrishnaes484
    @harikrishnaes4843 жыл бұрын

    can anyone help me all my scenes and all the game i developed have now came into an error and there is no scenes in there completely empty this was writteninconsole "Unknown error occurred while loading 'Assets/Scenes/SampleScene.unity'."

  • @faraday3833
    @faraday38334 жыл бұрын

    Hey Code Monkey this tutorial is so good. But i have a question about this automatic level generation system. If player falls from platform player should die. So i tried to add empty game object with 2D box collider under each level part but its not working right. That box collider can touch to other level parts. So what should i do?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    The simplest way is to use the player Y velocity and if it's too big you kill the player.

  • @faraday3833

    @faraday3833

    4 жыл бұрын

    @@CodeMonkeyUnity Oh how i couldn't think this! Very simple solution! Thank you so much you are awesome!

  • @funnyanimalworld7579
    @funnyanimalworld75793 жыл бұрын

    what if i want to despawn platforms that i have passed and if i return back i want them to respawn again?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    Then you would have to store a list keeping track of the type and spawn position.

  • @nauvalnavis6673
    @nauvalnavis667316 күн бұрын

    at 12:24 you were making new gameobject for levelpart2, and place the levelpart 2 at the end part1, my issues is why mine is different? when i put object inside the levelpart2 for platform, the levelpart2 gameobject change position? my levelpart2 "pivot" were at the center of platform instead of end of the part1, i hope you understand my words because im stuck here and this problem making my platform generation scrambled

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    15 күн бұрын

    Maybe your tool is set on Center instead of Pivot unitycodemonkey.com/video.php?v=qa5WBatZ830 Make sure you're checking the actual transform position

  • @nauvalnavis6673

    @nauvalnavis6673

    15 күн бұрын

    @@CodeMonkeyUnity thanks you helped me alot twice in another video, even those video were from many years ago

  • @d-o-double-g42
    @d-o-double-g424 жыл бұрын

    Hello. i have a question is it possible to make it so that the longer you press jump button the higher you jump with a jump limit?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Define a float field and increase it by Time.deltaTime while Input.GetKey(); is pressed

  • @d-o-double-g42

    @d-o-double-g42

    4 жыл бұрын

    @@CodeMonkeyUnity Ok thank you

  • @gorsayamyan1632
    @gorsayamyan16323 жыл бұрын

    Hi, I have a question about the platform behavior. Is it possible to modify the platform as in the game tiny wings in IOS or Dune in android. I am new in game developement thank you for advance ))

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    Sure, after spawning the platform you can do whatever you want with it like stretch it, rotate, move, etc.

  • @under4829
    @under4829 Жыл бұрын

    Hey, I have a lil problem taht make it impossible to do it, Unity tell me that the Player (The thing u put behind SerializedField) doesn't exist, it propose me PlayerPrefs, but then it say that GetPosition don't work with that :( I'm beginner so I would be really happy if you'd help me!

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    Жыл бұрын

    Sounds like you don't have any class named "Player"

  • @cyberguygame9096
    @cyberguygame90963 жыл бұрын

    @Code Monkey I want to destroy all the spawned GameObjects and create new ones each time I die. How can I do that? I tried adding the spawned parts to a list and destroy them each time I die and call the levelgenerator when I am starting again. but that seems not like the best way.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    That is indeed the best way, add them to the list when spawned, removed them from the list after you destroy them.

  • @axay06
    @axay062 жыл бұрын

    how to set maximum and minimum y value to level spawn so that it shouldn't spawn too above or below

  • @ubormaci5322
    @ubormaci53224 жыл бұрын

    In my script it don't gets the player. In "[SerializeField] private Player player;" the system never finds a player, it just questions "Type or namespace 'Player' could not be found (etc.).

  • @GaviTSRA

    @GaviTSRA

    4 жыл бұрын

    I had the same Problem. you make a script on the Player named Player. In the Player script you do: using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour { public Vector3 GetPositionPlayer; public void Update() { GetPositionPlayer = gameObject.transform.position; } } and in the random Generation script you do: private void Update() { if(Vector3.Distance(Player.GetComponent().GetPositionPlayer, lastEndPosition ) { SpawnLevelPart(); } } thats my soluion. i dont know if there is a bedder one but it works

  • @AliskHD
    @AliskHD3 жыл бұрын

    Hey, I used your tutorial and all worked fine till the moment I wanted to change the x y thing to the End Point Variable... Now my Generator works fine, it spawns the LevelPart_1 to the End Position but I have no idea why those platforms are invisible in the Gamemode, if I swop to the scene till the Game runs, I can see that generated LevelPart_1s but in the Gamemode, they are as I said invisible and I have no clue why... Also funny to know is that my player can jump on those invisible ones and also can collect coins on it. Please help me I stuck with this problem for now about 3 days and I can't find my mistake.

  • @AliskHD

    @AliskHD

    3 жыл бұрын

    Nvm I found my mistake in the comments xD

  • @Burakjones42

    @Burakjones42

    3 жыл бұрын

    @@AliskHD what is it pls help me

  • @matthijsromein7141
    @matthijsromein71414 жыл бұрын

    Hey Code Monkey! My level parts are spawning to far from eath other and also way to big! Can you or someone else help me?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Check the Scale of your prefabs and the Position or your end points.