Procedurally Generated 2D Terrain Procedural Generation

  Рет қаралды 23,114

ChronoABI

ChronoABI

Күн бұрын

Пікірлер: 61
@marynanovohorodska8784
@marynanovohorodska8784 Жыл бұрын
Thank you very much, I couldn't find a video about using rule tiles in world generation. Thank you!👏
@larsmaasanimaties4594
@larsmaasanimaties4594 2 жыл бұрын
i made this but instead of placing tiles. i just changed pixels on a texture. Works great. thank you
@apesign8668
@apesign8668 2 жыл бұрын
Great video. It's simple to follow and works just fine
@liam9996
@liam9996 3 жыл бұрын
TerrenGeneration!
@liam9996
@liam9996 3 жыл бұрын
@MioShimura The method name...
@v0id_d3m0n
@v0id_d3m0n 2 жыл бұрын
thank you! this was really helpful
@MrCrompz
@MrCrompz 3 жыл бұрын
1:26 i dont have the new components from the script
@FLStudioTutorialz
@FLStudioTutorialz 3 жыл бұрын
Great explanation. Thank you very much for your effort. It helps a lot.
@eduato_yt
@eduato_yt 2 жыл бұрын
great video dude!
@Tyquanfanboy
@Tyquanfanboy 3 жыл бұрын
i cant use the tile map you posted in the description
@Austeja608
@Austeja608 2 жыл бұрын
for some reason for me it only generates square same as in 9:21 entire code: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Tilemaps; using Unity.VisualScripting; public class generation : MonoBehaviour { [SerializeField] int width, height; [SerializeField] float smoothness; [SerializeField] float seed; [SerializeField] TileBase groundTile; [SerializeField] Tilemap groundTilemap; int[,] map; // Start is called before the first frame update void Start() { Generation(); } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Space)) { Generation(); } } void Generation() { groundTilemap.ClearAllTiles(); map = GenerateArray(width, height, false); map = terraingeneration(map); RenderMap(map, groundTilemap, groundTile); } public int[,] GenerateArray(int width, int height, bool empty) { int[,] map = new int[width, height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { map[x, y] = (empty) ? 0 : 1; } } return map; } public int[,] terraingeneration(int [,] map) { int perlinHeight; for (int x = 0; x < width; x++) { perlinHeight = Mathf.RoundToInt(Mathf.PerlinNoise(x / smoothness, seed) * height); for (int y = 0; y < perlinHeight; y++) { map[x, y] = 1; } } return map; } public void RenderMap(int[,] map , Tilemap groundTilemap, TileBase groundtilebase ) { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (map[x,y] == 1) { groundTilemap.SetTile(new Vector3Int(x, y, 0), groundtilebase); } } } } }
@solomonr4728
@solomonr4728 2 жыл бұрын
same
@xxxxxxxxxxxxxxxxxx12
@xxxxxxxxxxxxxxxxxx12 2 жыл бұрын
i have solution that worked, change this false to true "map = GenerateArray(width, height, false);".
@jaymhlurbaloyi7813
@jaymhlurbaloyi7813 3 жыл бұрын
can you do a 2D top-down version of this
@jkewlo
@jkewlo 4 жыл бұрын
Anyone having problems with the camera? and the bottom left meeting at the center of the camera?
@chronoabi
@chronoabi 3 жыл бұрын
Yeah its because the position (0,0,0) is the center of the video
@mysterymatt4761
@mysterymatt4761 3 жыл бұрын
@@chronoabi a little more explanation on this question please! :D ur rly one oft he greatest tutorial makers out here!
@danielreparos7050
@danielreparos7050 2 ай бұрын
Can you do this with tile?
@jiakai7254
@jiakai7254 Жыл бұрын
hi I cannot drag and drop things from hierarchy/assets to inspector pls help TT (Mac user)
@suprememarshal2015
@suprememarshal2015 2 жыл бұрын
Nice tutorial. How can I check for specific tile being next to the rule tile? I need to check if a tile is stone then use a stone variant and if it's next to dirt, it use dirt variant. But if I make two separate rule tiles, they won't work together when a dirt rule tile is next to a stone rule tile.
@pixelpat777
@pixelpat777 3 жыл бұрын
Great video thanks @ChronoABI !!! What if i wanted to add perlin noise octaves to this, where and what would i put?
@justadudewhoplaysgames2262
@justadudewhoplaysgames2262 Жыл бұрын
can someone help? its only generating a square instead of procedural square
@search_me_tilak
@search_me_tilak 4 жыл бұрын
Superb plz upload more videos
@chronoabi
@chronoabi 4 жыл бұрын
Sure 😊
@BigGuy07
@BigGuy07 2 жыл бұрын
How many people noticed that he typed in 69 and 420 in as the seed? Nice.
@Lubicabis
@Lubicabis 3 жыл бұрын
How can i put a Collider on the tiles, i use a rule tile, with the collide type "Sprite" but nothing happens if my player falls on it so he falls through it edit: solved it myself, just put a tilemap collider on the tilemap!
@Rpars20
@Rpars20 2 жыл бұрын
use the "TileMap Collider2D" on your groundTileMap
@JasonEllingsworth
@JasonEllingsworth 2 жыл бұрын
I am going nuts here, and since I am pretty sure I got the code from you or from the blog, maybe you can help. I need to have all the tiles have their own identity, or be their own instanced unique object. I use playmaker because I am very new. I need to basically attach an FSM either beforehand or on collision that destroys the tile if it is collided with a projectile. How do I achieve this? Currently in the hierarchy only one object is made that is the entire terrain with one Tilemap Collider. Any help you could give would be great and thank you.
@chronoabi
@chronoabi Жыл бұрын
Use game objects like prefabs of your individual tile so that all of them are seperate. Sorry for the late reply
@sripranav
@sripranav 3 жыл бұрын
Can we make it much more smoother?
@elithevil
@elithevil 4 жыл бұрын
great vid, tnx! i have one issue tho, for some reason pressing space doesnt do anything not does it show any errors..not sure why. ive also added debug log both before and after clearAllTiles and its shows both when i press space. code: [SerializeField] int width, height; [SerializeField] float smoothness; [SerializeField] float seed; [SerializeField] TileBase groundTile1; [SerializeField] Tilemap groundTilemap; int[,] map; // Start is called before the first frame update void Start() { seed = Random.Range(0, 100000); Generation(); } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Space)) { Generation(); } } void Generation() { groundTilemap.ClearAllTiles(); map = GenerateArray(width, height, true); map = TerrainGeneration(map); RenderMap(map, groundTilemap, groundTile1); }
@chronoabi
@chronoabi 4 жыл бұрын
Give me like your whole code bro I will test it out. Edit : I tried it and it works perfectly so give me your code
@elithevil
@elithevil 4 жыл бұрын
@@chronoabi using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Tilemaps; public class ProcGeneration : MonoBehaviour { [SerializeField] int width, height; [SerializeField] float smoothness; [SerializeField] float seed; [SerializeField] TileBase groundTile1; [SerializeField] Tilemap groundTilemap; int[,] map; // Start is called before the first frame update void Start() { seed = Random.Range(0, 100000); Generation(); } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Q)) { Generation(); } } void Generation() { groundTilemap.ClearAllTiles(); map = GenerateArray(width, height, true); map = TerrainGeneration(map); RenderMap(map, groundTilemap, groundTile1); } public int[,] GenerateArray(int width, int height, bool empty) { int[,] map = new int[width, height]; for (int x = 0; x < width; x++) { for (int y = +0; y < height; y++) { if (empty) { map[x, y] = 0; } else { map[x, y] = 1; } } } return map; } public int[,] TerrainGeneration(int[,] map) { int perlinHeight; for (int x = 0; x < width; x++) { perlinHeight = Mathf.RoundToInt(Mathf.PerlinNoise(x / smoothness, seed) * height); for(int y = 0; y < perlinHeight; y++) { map[x, y] = 1; } } return map; } public void RenderMap(int[,] map, Tilemap groundTileMap, TileBase groundTilebase) { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (map[x,y] == 1) { groundTilemap.SetTile(new Vector3Int(x, y, 0), groundTilebase); } } } } }
@chronoabi
@chronoabi 4 жыл бұрын
BRUH void Update() { if (Input.GetKeyDown(KeyCode.Q)) { Generation(); } } Did you try pressing Q 😂😂🤣
@elithevil
@elithevil 4 жыл бұрын
@@chronoabi yea ive just changed it for my preference but its the same thing. if i remove generation(); from start function, than i press q, it generates a world. but if its already generated nothing happens.. from what i understand it should remove all tiles than just make new ones.
@chronoabi
@chronoabi 4 жыл бұрын
That is because you have to put different seed value everytime before generating tile. Try putting "Seed = Random.Range(0,100000)" in the generation function just after your clearAllTiles
@Ahmed-ic9ft
@Ahmed-ic9ft 4 жыл бұрын
could u do a chunk feature so that only visible chunk is active so that to map can be bigger without lag
@chronoabi
@chronoabi 4 жыл бұрын
I am trying learn /figure that out. So once I do that I will
@Ahmed-ic9ft
@Ahmed-ic9ft 4 жыл бұрын
@@chronoabi this might help: github.com/Xonor13/Tranquility
@Ahmed-ic9ft
@Ahmed-ic9ft 4 жыл бұрын
also a vid: kzbin.info/www/bejne/mqGog2mvmdR2mac
@chronoabi
@chronoabi 4 жыл бұрын
@@Ahmed-ic9ft thankyou soo much bro. I was trying to figure out how to move through procedurally generated world for so long. Love you bro🤩
@zanspl
@zanspl 4 жыл бұрын
@@chronoabi This would be amazing to implement into this project :O
@zanspl
@zanspl 4 жыл бұрын
Hey so for some reason nothing gets spawned in, but there are no errors shown, could it be that i have my rule tile wrongly made?
@chronoabi
@chronoabi 4 жыл бұрын
Show me the code bro.
@zanspl
@zanspl 4 жыл бұрын
@@chronoabi public class ProceduralGeneration : MonoBehaviour { [SerializeField] int width, height; [SerializeField] TileBase groundTile; [SerializeField] Tilemap groundTilemap; int[,] map; void start() { map = GenerateArray(width, height, false); RenderMap(map, groundTilemap, groundTile); } public int [,] GenerateArray(int width, int height, bool empty) { int[,] map = new int [width, height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { map [x, y] = (empty) ? 0: 1; } } return map; } public void RenderMap(int[,] map, Tilemap groundTileMap,TileBase groundTilebase) { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (map[x,y] == 1) { groundTileMap.SetTile(new Vector3Int(x, y, 0), groundTilebase); } } } } }
@elithevil
@elithevil 4 жыл бұрын
@@zanspl i think it should be true, not false in: void start() { map = GenerateArray(width, height, false); RenderMap(map, groundTilemap, groundTile); }
@zanspl
@zanspl 4 жыл бұрын
@@elithevil Nope same with true, also first he tries it with false (9:16), and then shows us how when its true(9:45) it doesnt spawn anything :/
@chronoabi
@chronoabi 4 жыл бұрын
Bro your start Has a small "s" that's why ist not registering as the start function of the game. For a minute even I was "Wait like nothing is wrong here why is it not working" 😂😂
@lozD83
@lozD83 2 жыл бұрын
"Discription"
@The_Dxvil
@The_Dxvil 2 жыл бұрын
so i like this but use the next time other scripts that u dont need to use tilemaps and i used instead of tilemaps Sprite2d and it doesn't create bugs anymore because i was doing soething like that a long time ago and had so many bugs with it and now im making a 2d game with a terrain generator and it doesn't have bugs anymore because i changed so much with the terrain generator and added 2 scripts and it works fine even if i stress test it like i want 1000 generated and it makes it really fine and really fast
@chronoabi
@chronoabi Жыл бұрын
Sorry for the late reply. But thankyou soo much for the suggestion . I will try to implement this in my project and continue this series shortly
@gsc8902
@gsc8902 5 ай бұрын
69 420 hahaha "legendary values"
@КсенийКот
@КсенийКот 2 ай бұрын
This is very inefficient. You may rethink the code completely if you are making an implementation in a production project
@MysticpyMC
@MysticpyMC 2 жыл бұрын
[SerializeField] int width, height; [SerializeField] float smoothness; [SerializeField] float seed; [SerializeField] TileBase groundTile1; [SerializeField] Tilemap groundTilemap; int[,] map; // Start is called before the first frame update void Start() { seed = Random.Range(0, 100000); Generation(); } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Space)) { Generation(); } } void Generation() { groundTilemap.ClearAllTiles(); map = GenerateArray(width, height, true); map = TerrainGeneration(map); RenderMap(map, groundTilemap, groundTile1); }
@chronoabi
@chronoabi Жыл бұрын
what is this bro ??
@chronoabi
@chronoabi Жыл бұрын
Wait is that an Improved version of my code?? Bro thats quite cool 🤯
Two Way Of Cave Generation In Unity 2D
27:02
ChronoABI
Рет қаралды 10 М.
Делаю процедурную генерацию в Unity
13:15
99.9% IMPOSSIBLE
00:24
STORROR
Рет қаралды 25 МЛН
NEW CAMERA! 🎥 4.2.0 Alpha Update, From the Depths
28:08
BorderWise
Рет қаралды 1 М.
How To Make Custom Rule Tiles In Unity
7:20
Vinark117
Рет қаралды 16 М.
Minecraft terrain generation in a nutshell
25:49
Henrik Kniberg
Рет қаралды 162 М.
The Problem With Procedural Generation
17:57
Acerola
Рет қаралды 201 М.
A CHASM of Mediocrity - Procedurally Generated Metroidvanias
20:34
ingeniousclown Gaming
Рет қаралды 529 М.
PERLIN NOISE in Unity - Procedural Generation Tutorial
10:34
Brackeys
Рет қаралды 270 М.
I Made an Electronic Chessboard Without Turns
14:32
From Scratch
Рет қаралды 851 М.
How to Randomly Generate Levels (and Islands)
13:26
Jonas Tyroller
Рет қаралды 206 М.