Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Tuttle321 · Apr 12, 2021 at 05:06 AM · 2dteleportprocedural generationteleporting

how would I use teleport in in procedural generated rooms

OK To start I would like the rooms to be far away from each other. I want to make it so when u walk from one door you teleport to the door it is 'connected' to. How would I do this in procedurally generated rooms?

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sath · Apr 12, 2021 at 03:40 PM 0
Share

You need to know the doors positions. Is there any way to find those positions after creating the rooms?

avatar image Tuttle321 sath · Apr 12, 2021 at 04:09 PM 0
Share

That was what I was thinking but there Is no way to know where the door is. How would I add that?

avatar image Tuttle321 Tuttle321 · Apr 12, 2021 at 04:10 PM 0
Share

@sath ^^^^^

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Tuttle321 · Apr 12, 2021 at 08:10 PM

Ok, so there is a lot.

public enum Direction { up = 0, left = 1, down = 2, right = 3 };

 public class dungeonCrawlerController : MonoBehaviour
 {
     public static List<Vector2Int> positionsVisted = new List<Vector2Int>();
     private static readonly Dictionary<Direction, Vector2Int> directionMovementMap = new Dictionary<Direction, Vector2Int>
     {
         {Direction.up, Vector2Int.up},
         {Direction.left, Vector2Int.left},
         {Direction.down, Vector2Int.down},
         {Direction.right, Vector2Int.right}
     };

     public static List<Vector2Int> GenerateDungeon(genData dungeonData)
     {
         List<dungeonCrawler> dungeonCrawlers = new List<dungeonCrawler>();

         for (int i = 0; i < dungeonData.numberOfCrawlers; i++)
         {
             dungeonCrawlers.Add(new dungeonCrawler(Vector2Int.zero));
         }

         int iterations = Random.Range(dungeonData.iterationMin, dungeonData.iterationMax);

         for(int i = 0; i < iterations; i++)
         {
             foreach(dungeonCrawler dungeonCrawler in dungeonCrawlers)
             {
                 Vector2Int newPos = dungeonCrawler.Move(directionMovementMap);
                 positionsVisted.Add(newPos);
             }
         }

         return positionsVisted;

     }
 }

This is the Dungeon Crawler Controller.

public class generator : MonoBehaviour { public genData GenData;

 private List<Vector2Int> dungeonRooms;

 private void Start()
 {
     dungeonRooms = dungeonCrawlerController.GenerateDungeon(GenData);
     SpawnRooms(dungeonRooms);
 }

 private void SpawnRooms(IEnumerable<Vector2Int> rooms)
 {   
     roomController.instance.loadRoom("Start", 0, 0);
     foreach (Vector2Int roomLocation in rooms)
     {
         roomController.instance.loadRoom("Empty", roomLocation.x, roomLocation.y);
     }
 }

} This is the generator.

public class room : MonoBehaviour { public int width; public int Height;

 public int X;
 public int Y;

 void Start() 
 {
     if (roomController.instance == null)
     {
         Debug.Log("U Ducked Up");
         return;
     }

     roomController.instance.registerRoom(this);
 }

 void OnDrawGizmos() 
 {
     Gizmos.color = Color.red;
     Gizmos.DrawWireCube(transform.position, new Vector3(width, Height));
 }

 public Vector3 getRoomCenter()
 {
     return new Vector3 (X * width, Y * Height);
 }

} I think I need to add something here. This is the room script.

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;

public class roomInfo { public string name; public int X; public int Y; }

public class roomController : MonoBehaviour {
public static roomController instance;

 string currentWorldName = "Basement";

 roomInfo currentloadRoomData;

 Queue<roomInfo> loadRoomQueue = new Queue<roomInfo>();

 public List<room> loadedRooms = new List<room>();

 bool isLoadingRoom = false;

 void Awake()
 {
     instance = this;
 }


 void Update() 
 {
     UpdateRoomQueue();
 }

 void UpdateRoomQueue()
 {
     if (isLoadingRoom)
     {
         return;
     }

     if (loadRoomQueue.Count == 0)
     {
         return;
     }

     currentloadRoomData = loadRoomQueue.Dequeue();
     isLoadingRoom = true;

     StartCoroutine(loadRoomRoutine(currentloadRoomData));
 }

 public void loadRoom( string name, int x, int y)
 {   
     if (doesRoomExist(x, y))
     {
         return;
     }
     roomInfo newRoomData = new roomInfo();
     newRoomData.name = name;
     newRoomData.X = x;
     newRoomData.Y = y;

     loadRoomQueue.Enqueue(newRoomData);
 }

 IEnumerator loadRoomRoutine(roomInfo info)
 {
     string roomName = currentWorldName + info.name;

     AsyncOperation loadRoom = SceneManager.LoadSceneAsync(roomName, LoadSceneMode.Additive);

     while(loadRoom.isDone == false)
     {
         yield return null;
     }
 }

 public void registerRoom( room room)
 {
     room.transform.position = new Vector3 (
         currentloadRoomData.X * room.width,
         currentloadRoomData.Y * room.Height,
         0
     );

     room.X = currentloadRoomData.X;
     room.Y = currentloadRoomData.Y;
     room.name = currentWorldName + "-" + currentloadRoomData.name + " " + room.X + ", " + room.Y; 
     room.transform.parent = transform;

     isLoadingRoom = false;

     loadedRooms.Add(room);
 }

 public bool doesRoomExist ( int x, int y)
 {
     return loadedRooms.Find( item => item.X == x && item.Y == y) != null;
 }

} This is the Room Controller.

public class dungeonCrawler : MonoBehaviour { public Vector2Int Position { get; set;}

 public dungeonCrawler(Vector2Int startPos)
 {
     Position = startPos;
 }

 public Vector2Int Move(Dictionary<Direction, Vector2Int> directionMovementMap)
 {
     Direction toMove = (Direction)Random.Range (0, directionMovementMap.Count);
     Position += directionMovementMap[toMove];
     return Position;
 }

}

This is the last one. hope u can help! @sath

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Tuttle321 · Apr 13, 2021 at 04:07 AM 0
Share

https://www.youtube.com/watch?v=ClKUoD5J7mo&t=11s link to a part of the vid when he talks about doors. Have not added this yet.

avatar image Tuttle321 Tuttle321 · Apr 13, 2021 at 04:08 AM 0
Share

@sath ^^^^ Thanks so much for the help. Sorry if this is a lot!

avatar image sath Tuttle321 · Apr 13, 2021 at 06:32 AM 0
Share

ok this video is the solution to your problem. At some point in Room.cs you can have access to the room's doors as gameobjects, so you can know the positions.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

279 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Collision for Amount of Time 1 Answer

Player does not teleport to the right location 0 Answers

Advice on 2D Surface Terrain Generation Using Noise 1 Answer

teleport destination differs when player hits trigger from different positions 0 Answers

Ground dash is like a teleport 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges