![]() *Instead of using uniformly distributed random numbers (the default Math.random generator in most languages), I'm using (). Again the radius doesn't matter too much, but it should probably be proportionate to the number of cells. For each "cell" I spawn a Rectangle of random width and length within some radius. This is an arbitrary amount really, but the higher the number the larger the dungeon and in general more complexity.Ģ. First I set the number of cells I want to generate, say 150. #The interactive demo can be found here: ()ġ. It's pretty over-engineered, but hopefully will give anyone interested some ideas on generating dungeon layouts for their own games. In order to do so, it gets the values of the Horizontal and Vertical input and update the velocity accordingly.So today I'm going to be a little different and talk about one technical aspect of my game (), that is random procedural dungeon generation. ![]() So, it needs a speed attribute as a SerializeField and we implement the FixedUpdate method to move the player. This script will be very simple as the only thing we need is being able to move the Player. Now, create a new script called PlayerMovement and add it to the Player object. We can disable gravity in Edit -> Project Settings -> Physics2D and changing the gravity in the Y axis to 0. You also need to create a Tag called “Player”, and assign it to this object.Īlso, since this is a top-view game, we don’t want any gravity force. ![]() We do so by changing the size of the Box Collider 2D. Also, we need to reduce the size of the collider a little bit, so that the Player can walk through the doors. First, we don’t want the player to rotate when colliding with things, so we check the Freeze Rotation box of Rigidbody 2D. Notice that we need to do some changes in the components. Then, create a new GameObject called player from this sprite, and add a Box Collider 2D and a Rigidbody 2D to this object. First, select the “player” sprite in the Sprites folder, change the Pixels Per Unit to 30, the Sprite Mode to multiple and slice the prefab. We created the room for our dungeon, but we still need a player to move in the dungeon, and door to navigate through rooms. To make the floor tiles not collidable, select the floor tile in the Tile Palettes folder and change the Collider Type to None. ![]() However, this will make all tiles collidable. In order to do so, select the Tilemap object and add a Tilemap Collider 2D. The next step is making the walls in the room collidable, while the floor tiles are not. In the end, you should have something like this: Select the brush tool and paint the tilemap with the tiles you wish. Now, we can start creating our room tilemap using this tile palette. After creating the tile palette, drag and drop the tileset to the Tile Palette window. We need to create a new tile palette with the “terrains” tileset Unity will ask where you wish to save the palette, I suggest saving it in a separate folder called Tile Palettes. You also need to open the Tile Palette window (Window -> 2D -> Tile Palette). Now, right click on the Object Hierarchy tab, and select 2D object -> Tilemap. You need to do two things: (1) setting the Pixels Per Unit to 40 to make sure the tiles will appear in the right size (2) changing the Sprite Mode to Multiple, and then slicing it to be separated into individual tiles. First, download the sprites for this tutorial and we are going to configure the “terrains” sprite to be used for tilemaps. Unity provides tilemap generation features, so we are going to use them. Then, we can just load those tilempas later after generating the dungeon. The first thing we need to do is creating the tilemaps for the dungeon rooms. You can download the tutorial source code files here.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |