Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 GongagaSwordsman · Jun 06, 2019 at 10:09 AM · playerspawnprefabsprocedural generationrooms

Making the player position coherent based on which door he got in

So i'm making a dungeon crawler with rooms generated in a procedural manner - each room has its directions, and when the player enters one of the doors, i want it to come out from the door he actually used. How should i approach that? I would love a thorough explanation on how to approach this, instead of "just" code. Helps me think and reason by myself :D i'll link the scripts i'm using down below :

Rooms:

 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Tilemaps;
 
 public class Room
 {
     public Vector2Int roomCoordinate;
     public Dictionary<string, Room> neighbors;
     
 
     public Room (int xCoordinate, int yCoordinate)
     {
         this.roomCoordinate = new Vector2Int(xCoordinate, yCoordinate);
         this.neighbors = new Dictionary<string, Room>();
     }
 
     public Room (Vector2Int roomCoordinate)
     {
         this.roomCoordinate = roomCoordinate;
         this.neighbors = new Dictionary<string, Room>();
     }
 
     public List<Vector2Int> NeighborCoordinates ()
     {
         List<Vector2Int> neighborCoordinates = new List<Vector2Int>();
         neighborCoordinates.Add(new Vector2Int(this.roomCoordinate.x, this.roomCoordinate.y - 1));
         neighborCoordinates.Add(new Vector2Int(this.roomCoordinate.x + 1, this.roomCoordinate.y));
         neighborCoordinates.Add(new Vector2Int(this.roomCoordinate.x, this.roomCoordinate.y + 1));
         neighborCoordinates.Add(new Vector2Int(this.roomCoordinate.x - 1, this.roomCoordinate.y));
 
         return neighborCoordinates;
     }
 
     public void Connect (Room neighbor)
     {
         string direction = "";
         if (neighbor.roomCoordinate.y <this.roomCoordinate.y)
         {
             direction = "N";
         }
 
         if (neighbor.roomCoordinate.x > this.roomCoordinate.x)
         {
             direction = "E";
         }
 
         if (neighbor.roomCoordinate.y > this.roomCoordinate.y)
         {
             direction = "S";
         }
 
         if (neighbor.roomCoordinate.x < this.roomCoordinate.x)
         {
             direction = "W";
         }
 
         neighbors.Add(direction, neighbor);
     }
 
     public string PrefabName()
     {
         string name = "Room_";
         foreach (KeyValuePair<string, Room> neighborPair in neighbors)
         {
             name += neighborPair.Key;
         }
 
         return name;
     }
 
     public Room Neighbor(string direction)
     {
         return this.neighbors[direction];
     }
 
 
 
 }


 

Thanks in advance, i'm eager to hear how you would approach this

Comment
Add comment · Show 3
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 tormentoarmagedoom · Jun 06, 2019 at 10:21 AM 0
Share

$$anonymous$$an...

IF you pretend to get an answer, make it easy.... Delete all unneccessary code, and post only the important... We will not read 225 lines of code...

avatar image GongagaSwordsman tormentoarmagedoom · Jun 06, 2019 at 10:27 AM 0
Share

Sure, sorry! i thought it'd help you understand

avatar image tormentoarmagedoom GongagaSwordsman · Jun 06, 2019 at 10:44 AM 0
Share

much better now :D

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tormentoarmagedoom · Jun 06, 2019 at 10:49 AM

Hello.

Now, what i dont understand is what you need.

What you mean with "each room has its directions" and "come out from the door he actually used"

You mean if you left a room by the right side, character should enter into the next room by right side?

Then you only need to identify the doors position on the room, with a variable or using TAGs or calculate it using the transform position or rotation of the doors. And for example use trigger colliders to detect what door has been used, so you can have the information to spawn the caracter in the next room.

IF need something more specify, post some image or paint draw to understand what exactly you need:D

Bye!

Comment
Add comment · 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

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

132 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

Related Questions

enemy AI doesnt work when enemy is spawned but does if it is already in the scene 1 Answer

Problem with spawn player with RPC calls(c #) 1 Answer

Player Singleton and Spawning in new scene issue 0 Answers

Player only spawns upon play 1 Answer

How do you Place/Spawn a GameObject or Prefab in front of Player 2 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