1
0
Fork 0

Doors now should open correctly

This commit is contained in:
Saibotk 2018-04-24 03:52:38 +02:00
parent 755ed5ee65
commit c3bc5d1aaf
4 changed files with 22 additions and 4 deletions

View file

@ -1543,7 +1543,7 @@ Prefab:
- target: {fileID: 224150154901314796, guid: 460d856ea4eb14cedb5fecde1fe6d743,
type: 2}
propertyPath: m_AnchoredPosition.x
value: 0
value: 38.545288
objectReference: {fileID: 0}
- target: {fileID: 224150154901314796, guid: 460d856ea4eb14cedb5fecde1fe6d743,
type: 2}

View file

@ -68,10 +68,17 @@ public class Door : MonoBehaviour {
/// </summary>
/// <param name="collision"></param>
private void OnTriggerExit2D(Collider2D collision) {
// TODO only works correct for entering a room!
if ( collision.tag == "Player") {
Player player = collision.gameObject.GetComponent<Player>();
if ((boundingBox.offset - parent.GetCenter()).sqrMagnitude < ((Vector2) player.transform.position - parent.GetCenter()).sqrMagnitude)
return;
Vector2 centerToCollider = (Vector2) gameObject.transform.position - parent.GetPosition() + parent.GetCenter();
Vector2 centerToPlayer = (Vector2) player.gameObject.transform.position - parent.GetPosition() + parent.GetCenter();
if (centerToCollider.magnitude - 1 < centerToPlayer.magnitude) {
Debug.Log(centerToCollider.magnitude - 1);
Debug.Log(centerToPlayer.magnitude);
return;
}
Debug.Log("Leaving Trigger");
if(parent == null) {
Debug.Log("This door has no parent Room!");

View file

@ -217,6 +217,7 @@ public class GameController : MonoBehaviour {
doorRoot.transform.SetParent(goStart.transform);
start = goStart.AddComponent<Room>();
start.SetCenter(dg.start.GetCenter());
start.SetPosition(dg.start.roomPosition);
lt = lt.FindAll(x => x.tag == "door");
lt.ForEach(x => {
x.SetParent(doorRoot.transform);
@ -247,7 +248,7 @@ public class GameController : MonoBehaviour {
doorRootf.transform.SetParent(goFinish.transform);
ltf = ltf.FindAll(x => x.tag == "door");
finish = goFinish.AddComponent<Room>();
finish.SetPosition(dg.end.roomPosition);
finish.SetCenter(dg.end.GetCenter());
ltf.ForEach(x => {
x.SetParent(doorRootf.transform);
@ -279,6 +280,7 @@ public class GameController : MonoBehaviour {
doorRootg.transform.SetParent(groom.transform);
Room grom = groom.AddComponent<Room>();
grom.SetCenter(gr.GetCenter());
grom.SetPosition(gr.roomPosition);
ltg = ltg.FindAll(x => x.tag == "door");
ltg.ForEach(x => {
x.SetParent(doorRootg.transform);

View file

@ -9,6 +9,7 @@ public class Room : MonoBehaviour {
}
Vector2Int center;
Vector2Int position;
List<Door> doors;
List<Transform> spawnpoints;
@ -51,6 +52,14 @@ public class Room : MonoBehaviour {
center = v;
}
public void SetPosition(Vector2Int v) {
position = v;
}
public Vector2Int GetPosition() {
return position;
}
/// <summary>
/// Returns the Center as global from the generation. TODO change this
/// Is available after Generation and after Start Phase.