Better corridor generation
Added door as first corridor Changing from unlit and lit corridor
This commit is contained in:
@@ -156,7 +156,9 @@ MonoBehaviour:
|
|||||||
EndPoint: {fileID: 819094401162878122, guid: 03f2147e5a186fc408b959faa2f97e86, type: 3}
|
EndPoint: {fileID: 819094401162878122, guid: 03f2147e5a186fc408b959faa2f97e86, type: 3}
|
||||||
Player: {fileID: 6983871523237736218, guid: f0df263e5be65a041848d5a8bab85af1, type: 3}
|
Player: {fileID: 6983871523237736218, guid: f0df263e5be65a041848d5a8bab85af1, type: 3}
|
||||||
CorridorStraight: {fileID: 8047827979703692770, guid: 1a5d554c0c76caf4195cae47e098b79d, type: 3}
|
CorridorStraight: {fileID: 8047827979703692770, guid: 1a5d554c0c76caf4195cae47e098b79d, type: 3}
|
||||||
RoomDistance: 70
|
CorridorStraightUnlit: {fileID: 2016417306107577256, guid: 92d9025262a022a499862d352c2724ee, type: 3}
|
||||||
|
DoorCorridor: {fileID: 5603417387143431118, guid: 9eccbf5a500a0d2429e6008a713a49fd, type: 3}
|
||||||
|
RoomDistance: 40
|
||||||
minRoomsNumber: 3
|
minRoomsNumber: 3
|
||||||
maxRoomsNumber: 7
|
maxRoomsNumber: 7
|
||||||
--- !u!4 &23489964
|
--- !u!4 &23489964
|
||||||
|
|||||||
@@ -779,21 +779,53 @@ PrefabInstance:
|
|||||||
serializedVersion: 3
|
serializedVersion: 3
|
||||||
m_TransformParent: {fileID: 0}
|
m_TransformParent: {fileID: 0}
|
||||||
m_Modifications:
|
m_Modifications:
|
||||||
|
- target: {fileID: 1872598832695960773, guid: f0df263e5be65a041848d5a8bab85af1, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.w
|
||||||
|
value: 1
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 1872598832695960773, guid: f0df263e5be65a041848d5a8bab85af1, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.x
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 1872598832695960773, guid: f0df263e5be65a041848d5a8bab85af1, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.y
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 1872598832695960773, guid: f0df263e5be65a041848d5a8bab85af1, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.z
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 1872598832695960773, guid: f0df263e5be65a041848d5a8bab85af1, type: 3}
|
||||||
|
propertyPath: m_LocalEulerAnglesHint.y
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 6983871523237736218, guid: f0df263e5be65a041848d5a8bab85af1, type: 3}
|
- target: {fileID: 6983871523237736218, guid: f0df263e5be65a041848d5a8bab85af1, type: 3}
|
||||||
propertyPath: m_Name
|
propertyPath: m_Name
|
||||||
value: PlayerContainer
|
value: PlayerContainer
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7001416999833331379, guid: f0df263e5be65a041848d5a8bab85af1, type: 3}
|
||||||
|
propertyPath: m_LocalScale.x
|
||||||
|
value: 1.5
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7001416999833331379, guid: f0df263e5be65a041848d5a8bab85af1, type: 3}
|
||||||
|
propertyPath: m_LocalScale.y
|
||||||
|
value: 1.5
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7001416999833331379, guid: f0df263e5be65a041848d5a8bab85af1, type: 3}
|
||||||
|
propertyPath: m_LocalScale.z
|
||||||
|
value: 1.5
|
||||||
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 7001416999833331379, guid: f0df263e5be65a041848d5a8bab85af1, type: 3}
|
- target: {fileID: 7001416999833331379, guid: f0df263e5be65a041848d5a8bab85af1, type: 3}
|
||||||
propertyPath: m_LocalPosition.x
|
propertyPath: m_LocalPosition.x
|
||||||
value: 0
|
value: 0
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 7001416999833331379, guid: f0df263e5be65a041848d5a8bab85af1, type: 3}
|
- target: {fileID: 7001416999833331379, guid: f0df263e5be65a041848d5a8bab85af1, type: 3}
|
||||||
propertyPath: m_LocalPosition.y
|
propertyPath: m_LocalPosition.y
|
||||||
value: 0
|
value: 4.49
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 7001416999833331379, guid: f0df263e5be65a041848d5a8bab85af1, type: 3}
|
- target: {fileID: 7001416999833331379, guid: f0df263e5be65a041848d5a8bab85af1, type: 3}
|
||||||
propertyPath: m_LocalPosition.z
|
propertyPath: m_LocalPosition.z
|
||||||
value: 0
|
value: 15.09
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 7001416999833331379, guid: f0df263e5be65a041848d5a8bab85af1, type: 3}
|
- target: {fileID: 7001416999833331379, guid: f0df263e5be65a041848d5a8bab85af1, type: 3}
|
||||||
propertyPath: m_LocalRotation.w
|
propertyPath: m_LocalRotation.w
|
||||||
|
|||||||
@@ -14,13 +14,15 @@ public class MapGenManager : MonoBehaviour
|
|||||||
|
|
||||||
[Header("Corridor Prefabs")]
|
[Header("Corridor Prefabs")]
|
||||||
[SerializeField] private GameObject CorridorStraight;
|
[SerializeField] private GameObject CorridorStraight;
|
||||||
|
[SerializeField] private GameObject CorridorStraightUnlit;
|
||||||
|
[SerializeField] private GameObject DoorCorridor;
|
||||||
/*[SerializeField] private GameObject CorridorL;
|
/*[SerializeField] private GameObject CorridorL;
|
||||||
[SerializeField] private GameObject CorridorT;
|
[SerializeField] private GameObject CorridorT;
|
||||||
[SerializeField] private GameObject CorridorCross;
|
[SerializeField] private GameObject CorridorCross;
|
||||||
[SerializeField] private GameObject CorridorEnd;*/
|
[SerializeField] private GameObject CorridorEnd;*/
|
||||||
|
|
||||||
[Header("Generation Settings")]
|
[Header("Generation Settings")]
|
||||||
[SerializeField] private int RoomDistance = 5;
|
[SerializeField] private int RoomDistance = 3;
|
||||||
[SerializeField] private int minRoomsNumber = 3;
|
[SerializeField] private int minRoomsNumber = 3;
|
||||||
[SerializeField] private int maxRoomsNumber = 7;
|
[SerializeField] private int maxRoomsNumber = 7;
|
||||||
|
|
||||||
@@ -53,15 +55,15 @@ public class MapGenManager : MonoBehaviour
|
|||||||
// Place Generate Rooms
|
// Place Generate Rooms
|
||||||
for (int i = 0; i < roomCount; i++)
|
for (int i = 0; i < roomCount; i++)
|
||||||
{
|
{
|
||||||
Vector3 roomPos = GetGridPosition();
|
|
||||||
GameObject roomPrefab = mapPrefab[Random.Range(0, mapPrefab.Count)];
|
GameObject roomPrefab = mapPrefab[Random.Range(0, mapPrefab.Count)];
|
||||||
|
Vector3 roomPos = GetGridPosition(roomPrefab);
|
||||||
GameObject room = Instantiate(roomPrefab, roomPos, Quaternion.identity, transform);
|
GameObject room = Instantiate(roomPrefab, roomPos, Quaternion.identity, transform);
|
||||||
placedRooms.Add(room);
|
placedRooms.Add(room);
|
||||||
roomPositions.Add(roomPos);
|
roomPositions.Add(roomPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add End Point
|
// Add End Point
|
||||||
GameObject endPoint = Instantiate(EndPoint, GetGridPosition(), Quaternion.identity, transform);
|
GameObject endPoint = Instantiate(EndPoint, GetGridPosition(EndPoint), Quaternion.identity, transform);
|
||||||
roomPositions.Add(endPoint.transform.position);
|
roomPositions.Add(endPoint.transform.position);
|
||||||
placedRooms.Add(endPoint);
|
placedRooms.Add(endPoint);
|
||||||
|
|
||||||
@@ -73,31 +75,31 @@ public class MapGenManager : MonoBehaviour
|
|||||||
Vector3 endRoomPos = roomPositions[i + 1];
|
Vector3 endRoomPos = roomPositions[i + 1];
|
||||||
PrefabSize endRoom = placedRooms[i + 1].GetComponent<PrefabSize>();
|
PrefabSize endRoom = placedRooms[i + 1].GetComponent<PrefabSize>();
|
||||||
Vector3 firstCorridorPos = new Vector3(
|
Vector3 firstCorridorPos = new Vector3(
|
||||||
startRoomPos.x + startRoom.prefabSize.x / 2,
|
startRoomPos.x,
|
||||||
startRoomPos.y,
|
startRoomPos.y,
|
||||||
startRoomPos.z
|
startRoomPos.z + startRoom.prefabSize.y / 2
|
||||||
);
|
);
|
||||||
Vector3 lastCorridorPos = new Vector3(
|
Vector3 lastCorridorPos = new Vector3(
|
||||||
endRoomPos.x - endRoom.prefabSize.x / 2,
|
endRoomPos.x,
|
||||||
endRoomPos.y,
|
endRoomPos.y,
|
||||||
endRoomPos.z
|
endRoomPos.z - endRoom.prefabSize.y / 2
|
||||||
);
|
);
|
||||||
CreateCorridor(firstCorridorPos, lastCorridorPos);
|
CreateCorridor(firstCorridorPos, lastCorridorPos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Vector3 GetGridPosition()
|
private Vector3 GetGridPosition(GameObject roomPrefab)
|
||||||
{
|
{
|
||||||
Vector3 lastRoomPos = roomPositions[roomPositions.Count - 1];
|
Vector3 lastRoomPos = roomPositions[roomPositions.Count - 1];
|
||||||
|
PrefabSize lastRoom = placedRooms[placedRooms.Count - 1].GetComponent<PrefabSize>();
|
||||||
|
PrefabSize roomSize = roomPrefab.GetComponent<PrefabSize>();
|
||||||
|
|
||||||
// Convert grid units to world position
|
|
||||||
Vector3 roomPos = new Vector3(
|
Vector3 roomPos = new Vector3(
|
||||||
lastRoomPos.x + RoomDistance,
|
lastRoomPos.x,
|
||||||
lastRoomPos.y,
|
lastRoomPos.y,
|
||||||
lastRoomPos.z
|
lastRoomPos.z + lastRoom.prefabSize.y / 2f + roomSize.prefabSize.y / 2f + RoomDistance
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
return roomPos;
|
return roomPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,21 +108,53 @@ public class MapGenManager : MonoBehaviour
|
|||||||
// Calculate the distance
|
// Calculate the distance
|
||||||
float distance = Vector3.Distance(start, end);
|
float distance = Vector3.Distance(start, end);
|
||||||
PrefabSize corridorSize = CorridorStraight.GetComponent<PrefabSize>();
|
PrefabSize corridorSize = CorridorStraight.GetComponent<PrefabSize>();
|
||||||
|
PrefabSize corridorUnlitSize = CorridorStraightUnlit.GetComponent<PrefabSize>();
|
||||||
|
PrefabSize doorSize = DoorCorridor.GetComponent<PrefabSize>();
|
||||||
|
|
||||||
// Calculate the number of corridors needed
|
// Calculate the number of corridors needed
|
||||||
int corridorCount = Mathf.FloorToInt(distance / corridorSize.prefabSize.x);
|
int corridorCount = Mathf.FloorToInt(distance / corridorSize.prefabSize.y);
|
||||||
Debug.Log($"Creating {corridorCount} corridors from {start} to {end}");
|
Debug.Log($"Creating {corridorCount} corridors from {start} to {end}");
|
||||||
|
|
||||||
// Create corridors
|
// Create corridors
|
||||||
for (int i = 0; i < corridorCount; i++)
|
//Start with door
|
||||||
|
if (corridorCount > 0)
|
||||||
{
|
{
|
||||||
Vector3 pos = new Vector3(
|
Vector3 doorPos = new Vector3(
|
||||||
start.x + i * corridorSize.prefabSize.x + corridorSize.prefabSize.x * 0.5f,
|
start.x,
|
||||||
start.y,
|
start.y,
|
||||||
start.z
|
start.z + doorSize.prefabSize.y * 0.5f
|
||||||
);
|
);
|
||||||
Quaternion rotation = Quaternion.Euler(0, 90, 0);
|
Quaternion doorRotation = Quaternion.Euler(0, 0, 0);
|
||||||
|
GameObject doorCorridor = Instantiate(DoorCorridor, doorPos, doorRotation, transform);
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 1; i < corridorCount; i++)
|
||||||
|
{
|
||||||
|
if(i % 2 != 0)
|
||||||
|
{
|
||||||
|
// Create straight corridor
|
||||||
|
Vector3 pos = new Vector3(
|
||||||
|
start.x,
|
||||||
|
start.y,
|
||||||
|
start.z + i * corridorSize.prefabSize.y + corridorSize.prefabSize.y * 0.5f
|
||||||
|
);
|
||||||
|
Quaternion rotation = Quaternion.Euler(0, 0, 0);
|
||||||
GameObject corridor = Instantiate(CorridorStraight, pos, rotation, transform);
|
GameObject corridor = Instantiate(CorridorStraight, pos, rotation, transform);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Create unlit corridor
|
||||||
|
Vector3 pos = new Vector3(
|
||||||
|
start.x,
|
||||||
|
start.y,
|
||||||
|
start.z + i * corridorUnlitSize.prefabSize.y + corridorUnlitSize.prefabSize.y * 0.5f
|
||||||
|
);
|
||||||
|
Quaternion rotation = Quaternion.Euler(0, 0, 0);
|
||||||
|
GameObject corridorUnlit = Instantiate(CorridorStraightUnlit, pos, rotation, transform);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If there is not enough space to create corridors, throw an exception
|
||||||
|
else throw new System.Exception("Not enough space to create corridors");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,7 @@ public class MenuController : MonoBehaviour
|
|||||||
|
|
||||||
public void PlayButton()
|
public void PlayButton()
|
||||||
{
|
{
|
||||||
SceneManager.LoadScene("Podzemi");
|
SceneManager.LoadScene("GenTest");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SettingButtonn()
|
public void SettingButtonn()
|
||||||
|
|||||||
@@ -11,5 +11,8 @@ EditorBuildSettings:
|
|||||||
- enabled: 1
|
- enabled: 1
|
||||||
path: Assets/Scenes/Objekty.unity
|
path: Assets/Scenes/Objekty.unity
|
||||||
guid: 9fc0d4010bbf28b4594072e72b8655ab
|
guid: 9fc0d4010bbf28b4594072e72b8655ab
|
||||||
|
- enabled: 1
|
||||||
|
path: Assets/Scenes/GenTest.unity
|
||||||
|
guid: aaa0d7a56cbb4e24b851ccae66aa8925
|
||||||
m_configObjects: {}
|
m_configObjects: {}
|
||||||
m_UseUCBPForAssetBundles: 0
|
m_UseUCBPForAssetBundles: 0
|
||||||
|
|||||||
Reference in New Issue
Block a user