Adjustable room corridor prefab map generator

create a map generator based on rooms and corridors that will use prefabs. Make it so that I can adjust the quantity.

geminiGemini 2.5 Pro

Okay, here is a setup for a map generator using room and corridor prefabs, allowing you to specify the number of rooms.

This generator works on a grid system. It starts with one room and iteratively tries to attach new corridors and rooms to existing ones in random directions until the desired number of rooms is placed or it runs out of valid spots.

How to Use:

  1. Save the code as MapGenerator.cs inside an Assets/Scripts folder.
  2. Create an empty GameObject in your scene (e.g., name it "MapGenerator").
  3. Attach the MapGenerator.cs script to this GameObject.
  4. Create Prefabs:
    • Create at least one Room prefab (e.g., a simple cube or a more complex model representing a 5x5 grid area if roomDimensions is 5x5 and cellSize is 1). Ensure its pivot is at the center.
    • Create a Corridor prefab (e.g., a 1x1x1 cube if cellSize is 1). Ensure its pivot is at the center and it's oriented along the X-axis by default (the script rotates it for vertical corridors).
  5. Assign Prefabs:
    • Drag your Room prefab(s) into the Room Prefabs list in the Inspector.
    • Drag your Corridor prefab into the Corridor Prefab slot.
  6. Configure Settings:
    • Set Number Of Rooms to your desired quantity.
    • Adjust Room Dimensions (odd numbers like 5x5, 7x7 work best for centering), Corridor Length, and Cell Size to match your prefabs and desired scale.
    • Optionally, create another empty GameObject (e.g., "GeneratedMap") and drag it to the Generated Objects Parent slot for better scene organization.
  7. Generate:
    • Right-click the MapGenerator script component in the Inspector and select "Generate Map".
    • You can also call the GenerateMap() method from another script or trigger it at runtime.
    • Use "Clear Map" to remove the generated objects before generating again.

Assets\TEST SCRIPTS\Scripts\MapGenerator.cs(1,1): error CS0116: A namespace cannot directly contain members such as fields, methods or statements

geminiGemini 2.5 Pro

You are right, that error CS0116 indicates that code is outside of a class definition. It seems the csharp marker might have interfered, or the structure was slightly off.

Here is the corrected code for MapGenerator.cs, ensuring all code is properly contained within the class.

This version ensures the using statements are at the top, followed directly by the public class MapGenerator : MonoBehaviour { ... } definition, with all methods and fields inside the class braces. I also slightly adjusted the corridor/room connection point calculation and the corridor rotation logic comments for clarity depending on your prefab's default orientation.

Make a map generator like in scp sl

geminiGemini 2.5 Pro

Okay, creating a map generator exactly like SCP: Secret Laboratory is quite complex, involving distinct zones (LCZ, HCZ, EZ, Surface), specific mandatory rooms (containment chambers, checkpoints, elevators), unique room shapes, and intricate connection logic.

This example provides a simplified, foundational approach inspired by SCP:SL's structure. It focuses on generating distinct "zones" sequentially, each using its own set of room/corridor prefabs, and connecting them at specific points (simulating elevators or major checkpoints).

Key Concepts Implemented:

  1. Zone-Based Generation: The map is built zone by zone (e.g., LCZ -> HCZ -> EZ).
  2. Zone-Specific Prefabs: Each zone uses its own list of room and corridor prefabs.
  3. Connector Prefabs: Special prefabs are used to mark the transition points between zones (e.g., an "Elevator Shaft" prefab).
  4. Sequential Placement: Generation starts in LCZ. When an "upward connector" (like an elevator shaft leading to HCZ) is placed, LCZ generation stops, and HCZ generation begins relative to that connector's position. The same process links HCZ and EZ.
  5. Grid System: A global grid prevents overlaps between all placed rooms/corridors across zones.

Limitations of this Simplified Version:

  • Doesn't guarantee specific mandatory rooms (like 914 or 173's chamber) will spawn, relying on them being included in the prefab lists and random chance.
  • Uses the same basic room/corridor attachment logic as before, not complex pre-defined zone modules or unique room shapes found in SCP:SL.
  • Connectors are simple markers; actual elevators or interactive elements need separate implementation.
  • Assumes a primarily 2D layout (though easily adaptable to 3D by changing Vector2Int to Vector3Int and adjusting GridToWorld).

Here's the code:

How to Set Up:

  1. Save the code as SCPSL_MapGenerator.cs.
  2. Create an empty GameObject and attach this script.
  3. Create Prefabs:
    • Rooms: Make various room prefabs for LCZ, HCZ, and EZ. Ensure their pivots are centered. Include prefabs for any specific rooms you want (even if placement isn't guaranteed yet).
    • Corridors: Create corridor segment prefabs (e.g., a 1x1xcellSize segment). You'll need one type per zone if you want different visuals (e.g., LCZ_Corridor, HCZ_Corridor). Assume the prefab's forward direction is along the +X axis.
    • Connectors: Create prefabs representing the transition points between zones. For example:
      • Elevator_Shaft_LCZ_to_HCZ: This will be placed in LCZ to mark where HCZ should connect.
      • Elevator_Shaft_HCZ_to_EZ: Placed in HCZ.
      • (Optional) Gate_A_Connector / Gate_B_Connector: Placed in EZ if you want specific exit points.
  4. Configure the Inspector:
    • Expand the "Zone Configurations" section.
    • For each zone (LCZ, HCZ, EZ):
      • Drag the corresponding Room prefabs into the Room Prefabs list.
      • Drag the zone's Corridor prefab into Corridor Prefab.
      • Drag the connector prefab that leads OUT of this zone into Exit Connector Prefab (e.g., for LCZ settings, assign Elevator_Shaft_LCZ_to_HCZ). Leave empty for the final zone (EZ) if it has no specific required exit marker.
      • Set the Target Room Count and default Room Dimensions/Corridor Length.
    • Set the global Cell Size.
    • Optionally assign a Generated Map Parent.
  5. Generate: Right-click the script component -> "Generate SCP Map".

This provides a starting point. You'd need to enhance it significantly for a true SCP:SL clone, particularly by adding logic for mandatory room placement, more complex room shapes/connections, and actual elevator functionality.

add points to connect the corridors add the ability to select multiple corridors

geminiGemini 2.5 Pro

Okay, let's modify the generator to use explicit connection points on prefabs and allow for multiple corridor types per zone.

1. Create the Connection Point Marker Script:

This simple script will be attached to GameObjects on your room prefabs to mark where corridors can connect.

How to Set Up (Updated):

  1. Save Scripts: Make sure both ConnectionPointMarker.cs and the updated SCPSL_MapGenerator.cs are saved in your project (e.g., Assets/Scripts).
  2. Modify Room Prefabs:
    • Open your Room prefabs (for all zones, including Exit Connectors).
    • Create empty GameObjects as children of the room prefab.
    • Position these empty GameObjects exactly where you want a corridor to connect (e.g., in the middle of a doorway).
    • CRITICAL: Rotate each empty GameObject so its local Z-axis (the blue arrow in the editor) points directly outwards from the room, along the path the corridor should take.
    • Attach the ConnectionPointMarker.cs script to each of these empty GameObjects.
  3. Configure Generator Script:
    • Select the GameObject with the SCPSL_MapGenerator script.
    • In the Inspector, under "Zone Configurations":
      • The Corridor Prefab field is now Corridor Prefabs. Drag one or more corridor prefabs for that zone into this list. If you only have one type, just add that one.
      • Ensure Room Prefabs and Exit Connector Prefab are still assigned correctly.
      • Default Room Dimensions is now mainly used for the initial bounding box check; the connection points dictate the actual connections.
  4. Generate: Right-click the script component -> "Generate SCP Map".

Now, the generator will look for ConnectionPointMarkers on your rooms to determine where to branch off with corridors, and it will randomly pick from the available Corridor Prefabs for each zone when building connections.

Google

gemini

Gemini 2.5 Pro

Code editing is temporarily disabled

No file selected