V
V
Vladimir Kuznetsov2018-03-11 14:11:35
C++ / C#
Vladimir Kuznetsov, 2018-03-11 14:11:35

How to implement transitions between generated locations (Unity 2D)?

I am developing a 2d (top view) game on Unity with randomly generated locations similar to those in roguelike games. Now the game has 2 scenes, namely the menu and "main", in which I planned to load the generated locations. Faced such a problem: according to the idea, the player can move from one location to the neighboring ones by entering the trigger on the edge of the location, like in fallouts 1-2, it turns out that from the first location you can go to the location above/below/to the right/to the left of the current one, while the location from which the player moves must be serialized, i.e. save the position of objects, enemies and other objects, so that in the future, when returning to the original location, it will already be generated and loaded from the "save". In general, there was confusion about how to implement this.
For example, let's take world generation in Minecraft: when creating a new world (essentially a save), this world weighs a couple of megabytes, since only a couple of chunks are generated, but as the player advances, the world is generated further and grows, while you can return to the respawn place and it will remain the same.
I'm trying to make the location as a class with the fields List floor, List items, etc., and when generating the location, add the corresponding GO to the lists, as well as fields like GameObject locationTop/Right/Left/Bot, and store links to the GO in these fields already created locations, but something tells me that this is a deliberately wrong implementation.
Please explain how, in terms of performance, it is better to implement this or direct it in which direction to dig. Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Daniil Basmanov, 2018-03-12
@manullol

If your world is not infinite, then one of the possible approaches is to generate your own seed for each location at the start of creating the world, then during the game, if you somehow get into this location (on foot, teleport or something else), then another generator takes the saved seed and creates that location from scratch. If you then somehow make changes to this location, then you save these changes separately, whether it be dropped items or demolished walls. If you later want to return to this location, then you take the saved seed, generate the location from scratch and apply the changes. Another option is to take its coordinates as a seed for a location, such a scheme is also suitable for an infinite world, but not in every game you can find the level coordinates in an obvious way.
All this fuss with seeds is needed for several reasons. First, you need it as a developer to test generators. Ideally, your generators should be completely deterministic, from the same seed you should always generate the same world, no matter how it is researched. If this is not the case, then you will then suffer to debug the generation process, while with the seed you simply save it, write it to the logs, and then use it at any time to recreate the problem situation. Secondly, the presence of an explicit seed in procedurally generated games is already an expectation of the genre, they are shared on the Internet, they are used for weekly tests, etc.
Generally speaking, on the topic of generators and seeds, I can advise this articlefrom the developer of Cogmind, everything is the same as I said, only in more detail.

T
twobomb, 2018-03-11
@twobomb

If we take minecraft or games like it, then to generate the game uses seed (seed) the usual number from which all subsequent random numbers are generated, but these random numbers are always in the same sequence, which means that the world will look the same for everyone, but it’s worth changing at least one digit generation sequence completely changes and the world is completely different.
As for saving, it’s worth saving only what the player changed, put a block, broke a window, threw out a weapon, and of course what you need, but you don’t need to save the world, it will always be the same if it is generated from one number.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question