Infinite Procedural Terrain in Unity

preview_player
Показать описание

The project is using Unity 2017.3.0. Just FYI.

-----------------------------

Update: Unity 2017.2.0 introduced the Vector2Int class. It doesn't make a difference, but it makes more sense to use it to keep track of tiles. It didn't exist when I originally made it.

-----------------------------

Update Update: I didn't realize that It doesn't have the correct UV map to support custom textures. If you want to use a custom texture with the ground, you can get the updated script from this link: (see comments for changes)

Directions:

(All in advanced folder, make sure you're in the advanced scene)

Replace GenerateMesh script with new GenerateMesh script.

The Terrain Thingy prefab should say it's missing a component. Update it with the new GenerateMesh script.

In TerrainController, at the top somewhere, define a new variable:
[SerializeField]
private float uvScale = 1;

In TerrainController, around line 160, add a line:
gm.UVScale = uvScale;

Thank you to Rato Caverna in the comments for providing this fix.
Рекомендации по теме
Комментарии
Автор

I can't remember the last time I've seen someone actually use the light theme for VS

coleslater
Автор

That`s awesome!! You made it work perfectly, I was working on this for 4 weeks now, and always finding a huge amount of bugs, but now I can try with your code! Thaaaanks!
PS: If I can give you a tip about the video, don`t make one so long, as this video explained a lot of different things, make a serie, so it`s faster and easier to find what we`re looking for ;)

AronautAaron
Автор

thank you for taking the time to make this video! it helped me out!

Notion
Автор

1:27 using example
1:55 simple version


14:50 [start using normal script]
15:15 making water
18:15 tree 🎄🌴
20:45 script explain
26:45 player zero script
39:45 place object

35:45 making perlin noise imagin

mostsoul
Автор

This is an excellent video, thanks for sharing!

NatusPella
Автор

Awesome, thanks for this. I have been struggling with this topic for a while! I am trying to assign my own material to the tile but no matter how I adjust it always comes out like water etc. I am not using any bumps, ridges etc just a flat floor with hopefully my texture. Can you advise?

Piginhatwoodcrafts
Автор

Great Tutorial Thank you!, just a question: How could i make the terrain move towards player?, like an infinite runner kind of game?

arthuralexei
Автор

That is a great video indeed, thanks for sharing it.
I'm trying to make it work with textures but I'm a failure at UV mapping, do you have do any progress on it?

RatoCavernaBR
Автор

I did not not not not not not not not understand everything! keep up the good work!

winterboltgames
Автор

thank you for the amazing video and codes really saved me lot of time
but what if i want the cells to be square (four corners) how can i do that ? when i try to change the vertexCount value in the GenerateMeshSimple code it return error (The number of supplied triangle indices must be a multiple of 3.)

mohanedmohsen
Автор

It seems that in TileFromPosition you are dividing the position by the length of tiles and then you want to round. That is, round up any decimal places equal to or greater than 0.5 or round down decimal places less than 0.5. Is there not a simple rounding function to do that? Perhaps not if you used Floor and then simply added 0.5 to ensure that it worked the same as normal rounding works.

Snowy
Автор

Has anyone managed to modify this to add layers of noise? I'm having trouble adding things like octaves, lacunarity and persistance.

williammena
Автор

Hi! This video really helped me out and remarkably I kind of understand it!
Now I’ve been fiddling with the trees trying to make structures that randomly spawn (I want to make randomly spawning ruins) kind of like villages in minecraft but I just can’t seem to do it.
Do you think you could help me? It’s fine if you don’t have time your tutorial helped a lot either way.

sensual
Автор

Thank you for the good video
Is there any way to change the background of the first infinite map?
I want to flatten the terrain

enmmxnr
Автор

how to add more pleceable object i have a rock and a tree and i neeed more trees and less rocks how can i do that in this script

stmproduction
Автор

How can I add water after a certain time or as a level in my game.
I am using ur script to create infinite terrain which is working fine but I want water to spawn and the terrrain to vanish at a certain point.
Pleas help

jidnyesh.j
Автор

How would I be able to save the world? For example, If I broke down a few trees, how would I go about saving the modified state of the world?

ARAPHELLE
Автор

i am getting an error at
i can t place more objects than 1

flint
Автор

I'm trying to do something like this, looking at the comments, apparently, the Procedural Toolkit is very different now. Is it still possible to do this with the new one? Also, how could I make this randomly generate, but not replace the randomly generated tiles if you go over them again, (like, I'm trying to make a low poly neighborhood, with randomly generated house tiles. I think I was originally thinking I was going to make roads random too, but I think that would be too crazy, so I'm going to probably make it be a grid of roads, with random tiles connected to the sides of the road, surrounding the road.)? Sorry, essentially, there'll be a tile, which will have a randomly generated house in the middle, with randomly generated trees, and such. But I don't want them to get replaced, once they generate, I want them to stay. My thinking of doing this is because I'm going to probably try to make this project / game multiplayer, and I want it to be the same.
Sorry if this question doesn't make sense.
Thanks!

FoxGAMING-NTF
Автор

I agree with your usage of the word 'Tile'. IMHO Tile is better because it is 2D (a terrain mesh) whereas a Chunk is 3D containing information on everything with the chunks bounds.

digiacomtech