small fixes in portal clones and Terminal B

This commit is contained in:
2022-11-28 20:52:00 +01:00
parent 8a708e27b8
commit efe3cceba1
8 changed files with 131 additions and 40 deletions

View File

@@ -7,7 +7,6 @@ using UnityEngine;
namespace EscapeRoomEngine.Portal.Runtime
{
[RequireComponent(typeof(Collider))]
public class Portal : DoorState
{
public static readonly Matrix4x4 HalfRotation = Matrix4x4.Rotate(Quaternion.Euler(0, 180, 0));
@@ -31,9 +30,6 @@ namespace EscapeRoomEngine.Portal.Runtime
private void Awake()
{
// check whether the collider is set up correctly
if (!GetComponent<Collider>().isTrigger) throw new Exception("Collider must be a trigger.");
DoorEvent += (_, type) =>
{
if (type == DoorEventType.Connected)

View File

@@ -1,5 +1,7 @@
using System;
using UnityEngine;
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
using LogType = EscapeRoomEngine.Engine.Runtime.Utilities.LogType;
namespace EscapeRoomEngine.Portal.Runtime
{
@@ -57,6 +59,8 @@ namespace EscapeRoomEngine.Portal.Runtime
{
if (hasClone)
{
Logger.Log($"Enabled {clone}", LogType.Portals);
clone.portal = at;
clone.gameObject.SetActive(true);
}
@@ -66,6 +70,8 @@ namespace EscapeRoomEngine.Portal.Runtime
{
if (hasClone && at.Equals(clone.portal)) // don't disable clones that are already at a different portal
{
Logger.Log($"Disabled {clone}", LogType.Portals);
clone.portal = null;
clone.gameObject.SetActive(false);
}
@@ -73,6 +79,8 @@ namespace EscapeRoomEngine.Portal.Runtime
public void Teleport(Portal from, Portal to)
{
Logger.Log($"Teleported {this} from {from} to {to}", LogType.Portals);
var m = to.portalTransform.localToWorldMatrix * Portal.HalfRotation *
from.portalTransform.worldToLocalMatrix * traveller.localToWorldMatrix;
traveller.SetPositionAndRotation(m.GetPosition(), m.rotation);

View File

@@ -36,8 +36,8 @@ namespace EscapeRoomEngine.Portal.Runtime
public void UpdatePosition(Transform cloning)
{
var m = portal.transform.localToWorldMatrix * Portal.HalfRotation *
portal.linkedPortal.transform.worldToLocalMatrix * cloning.localToWorldMatrix;
var m = portal.portalTransform.localToWorldMatrix * Portal.HalfRotation *
portal.linkedPortal.portalTransform.worldToLocalMatrix * cloning.localToWorldMatrix;
transform.SetPositionAndRotation(m.GetPosition(), m.rotation);
}
}