- Home /
Object transform not moving to other transform correctly
Hi all,
I'm trying to design a dungeon generation system and I've been having problems with BuildPoints and their transforms. It's a simple thing that I truely can not figure out.
Basically each room has a set number of build points (It can be different for every room.
The system ( as of right now) gets a list of all the available buildpoints that are open and puts it in a list.
Then it selects a random room from a collection. The selects a build point from that room. And then move the room that build point so it looks flush and the rooms look actually connected.
However I'm having trouble with thetransform part. Doesn't seem to want to work. Based on the build point I seem to get different results.
The red line is the Build that was selected
Completely Seperate
Stacking
Obviously it shouldn't be this hard but I don't know why it is.
The code is as followed
void BuildRooms() {
for (int x = 0; x < maxRooms; x++)
{
//TODO: MOve this into it's own function-------
//Grab all openBuild Points
var buildPoints = new List<BuildPoint>();
foreach (BuildPoint buildPoint in FindObjectsOfType<BuildPoint>())
{
if (buildPoint.buildPointState.Equals(BuildPointState.Open))
{
buildPoints.Add(buildPoint);
}
}
var oldBuildPoint = buildPoints[Random.Range(0, buildPoints.Count)];
Debug.Log(oldBuildPoint);
var newRoom = collection.Templates[Random.Range(0, collection.Templates.Count)].room.GetComponent<Room>();
Debug.Log(newRoom);
var newRoomBuildPoint = newRoom.GetComponent<Room>().buildPoints[Random.Range(0,newRoom.buildPoints.Count)];
Debug.Log(newRoomBuildPoint);
var spawnedRoom = Instantiate(newRoom.gameObject, Vector3.zero, Quaternion.identity, transform);
Debug.Log(spawnedRoom);
//Set the selected room to world position of the build point;
newRoom.transform.position = oldBuildPoint.transform.position -
newRoomBuildPoint.transform.position;
//Rotate around the build point
float roomRot = oldBuildPoint.transform.rotation.eulerAngles.y -
newRoomBuildPoint.transform.rotation.eulerAngles.y + 180;
spawnedRoom.transform.RotateAround(newRoomBuildPoint.gameObject.transform.position,Vector3.up,roomRot);
oldBuildPoint.buildPointState = BuildPointState.Closed;
//TODO: -----------------------------------
}
}
}
If someone whats to help me and point me in the right direction that would be great. Thanks!