Create 2D Top Down Chunks
I was wondering how I can make a chunk system in Unity2D. My map is too big, I want to make a system of chunks, to unload and load the parts of the map, as the player progresses.
I need to do this for the game to be more optimized, but I don't know how to do that.
I've already tried to create some code or search for examples on the internet, but unfortunately I didn't find anything.
CodePudding user response:
The problem in the question can be solved with a lot of strategies, but all of them require good programming experience. I can give you an idea to send you on a good path, but without writing code, because for each project the code would change. Think you have 4 parts. These parts are rectangular or square and form a large rectangle much larger than the player's view. The player can start from any position, but for the example imagine that he is in the first rectangle, the one at the bottom left. We call the rectangles A, the lower left one, B the lower right one, C the upper left one, and D the upper right one. When the player goes to the right, walking for a while he will arrive in rectangle B. If it continues to move to the right at some point it will arrive at the end of rectangle B and at this point you have to place rectangle A, which is on the left, next to the right side of rectangle B, so that the player does not see the end. We now have rectangle A on the right and rectangle B on the left. If the player continues to go to the right, he will reach the boundary of rectangle A, and there you have to move rectangle B to the right of the terrace A, as in the initial situation. If the player goes to the left you have to think in the opposite way. If it goes up, you have to think about the same system, but instead of with rectangles A and B, with rectangles A and C or B and D: it depends on which one it is. This is one way to have an infinite map. You can customize this system to have not 4 blocks but more, and to get the result you want.
If I was helpful to you, you can thank me by marking my answer as accepted :)