#3D Procedural generation

1 messages · Page 1 of 1 (latest)

worn drum
#

Hello everyone. I have a problem with room generation. I recently found an algorithm for generating rooms, but it was more focused on 2D. My problem is with generating large rooms (L-shaped, large, horizontal and vertical). Plus there are problems with rotation and coordinates. Does anyone have any ideas how I can fix this?

#

(There is a 3 videos in total. I got a problems with second: https://www.youtube.com/watch?v=0robI3xZ32g&list=PLsPeQQshJs0z6sNzZz30da9Sc5Vx7dyEs

I don`t understand how to make SetRoomForm. In video guy just changing sprite, but how to make it with prefabs?
Also i got issues with rotation)

Continuing on our Binding of Isaac Map Generation - we are now adding in the larger room variations!

Part 1: https://youtu.be/cIkfyThuFkg

Part 3: https://youtu.be/V9BODsU3QvU

Access the full source code here: https://github.com/GarnetKane99/Binding-Of-Isaac_Map-Generator

Wanna say thanks? Buy me a coffee!
https://buymeacoffee.com/gamedevgar...

▶ Play video
final anchor
#
  1. Sharing code properly would help.
  2. Explaining the issue a bit better would help as well. Do you basically need to rotate GameObjects?
#

!code

iron loomBOT
worn drum
# final anchor 1. Sharing code properly would help. 2. Explaining the issue a bit better would ...

I have a problem with transferring the logic to 3D. In the original video, the author changes the sprite when generating large rooms. How can I adapt this with prefabs of 3D objects?

Room.cs

using TMPro;
using UnityEngine;
using System.Collections.Generic;

public class Room : MonoBehaviour
{
    public int index;
    public int value;

    public TMP_Text roomSign;
    public GameObject roomForm;

    public void SetRoomSign(string signText)
    {
        roomSign.text = signText;
    }

    // in original video it just changing sprite
    // public void SetRoomSprite(Sprite roomIcon)
    //{
    //  roomSprite.sprite = roomIcon
    //}

    public void SetRoomForm(GameObject roomForm)
    {
        // How to apapt it in 3D?
    }

    public void RotateRoom(List<int> connectedRooms)
    {
        connectedRooms.Sort();
        index = connectedRooms[0];

        if (connectedRooms.Contains(index + 1) && connectedRooms.Contains(index + 10))
        {
            ApplyRotation(-90);
        }

        else if (connectedRooms.Contains(index + 1) && connectedRooms.Contains(index + 11))
        {
            ApplyRotation(180);
        }

        else if (connectedRooms.Contains(index + 9) && connectedRooms.Contains(index + 10))
        {
            ApplyRotation(90);
        }
    }

    public void ApplyRotation(float angle)
    {
        transform.rotation = Quaternion.Euler(0, 0, angle);
    }
}
#

MapGenerator.cs

private void SpawnLargeRoom(List<int> largeRoomIndexes)
    {
        Room newRoom = null;

        int combinedX = default;
        int combinedY = default;
        float offset = roomSize / 2f;

        for (int i = 0; i < largeRoomIndexes.Count; i++)
        {
            int x = largeRoomIndexes[i] % 10;
            int y = largeRoomIndexes[i] / 10;
            combinedX += x;
            combinedX += y;
        }

        if (largeRoomIndexes.Count == 4)
        {
            Vector3 position = new Vector3(combinedX / 4 * roomSize + offset, -combinedY / 4 * roomSize - offset);

            newRoom = Instantiate(roomPrefab, position, Quaternion.identity);
            newRoom.SetRoomForm(largeRoom);
        }

        if (largeRoomIndexes.Count == 3)
        {
            Vector3 position = new Vector3(combinedX / 3 * roomSize + offset, -combinedY / 3 * roomSize - offset);
            newRoom = Instantiate(roomPrefab, position, Quaternion.identity);
            newRoom.SetRoomForm(lShapeRoom);
            newRoom.RotateRoom(largeRoomIndexes);
        }

        if (largeRoomIndexes.Count == 2)
        {
            if (largeRoomIndexes[0] + 10 == largeRoomIndexes[1] || largeRoomIndexes[0] - 10 == largeRoomIndexes[1])
            {
                Vector3 position = new Vector3(combinedX / 2 * roomSize, -combinedY / 2 * roomSize - offset);
                newRoom = Instantiate(roomPrefab, position, Quaternion.identity);
                newRoom.SetRoomForm(verticalRoom);
            }
            else if (largeRoomIndexes[0] + 1 == largeRoomIndexes[1] || largeRoomIndexes[0] - 1 == largeRoomIndexes[1])
            {
                Vector3 position = new Vector3(combinedX / 2 * roomSize + offset, -combinedY / 2 * roomSize);
                newRoom = Instantiate(roomPrefab, position, Quaternion.identity);
                newRoom.SetRoomForm(HorizontalRoom);
            }
        }

        spawnedRooms.Add(newRoom);
    }
final anchor