Example #1
0
        public void OnTriggerStay(Collider other)
        {
            if (!portalIsEnabled)
            {
                return;
            }

            // Player teleports are handled through a CompositeMagicTrigger to make it easier to ensure they are
            // in the right position and moving the correct direction before triggering teleport
            if (!other.TaggedAsPlayer())
            {
                Vector3 closestPoint             = ClosestPoint(other.transform.position, true);
                bool    objectShouldBeTeleported = Mathf.Sign(Vector3.Dot(PortalNormal(), (other.transform.position - closestPoint).normalized)) > 0;
                if (!objectShouldBeTeleported)
                {
                    return;
                }

                PortalableObject portalableObj = other.gameObject.GetComponent <PortalableObject>();
                if (portalableObj != null && objectsInPortal.Contains(portalableObj))
                {
                    TeleportObject(portalableObj);

                    // Swap state to the other portal
                    objectsInPortal.Remove(portalableObj);
                    otherPortal.objectsInPortal.Add(portalableObj);
                    portalableObj.sittingInPortal = otherPortal;
                }
            }
        }
Example #2
0
        public void TeleportObject(PortalableObject portalableObject, bool transformVelocity = true)
        {
            portalableObject.BeforeObjectTeleported?.Invoke(this);

            TransformObject(portalableObject.transform, transformVelocity);

            portalableObject.OnObjectTeleported?.Invoke(this);
        }
Example #3
0
        public void OnTriggerExit(Collider other)
        {
            if (other.TaggedAsPlayer())
            {
                return;
            }

            PortalableObject portalableObj = other.gameObject.GetComponent <PortalableObject>();

            if (portalableObj != null && objectsInPortal.Contains(portalableObj))
            {
                objectsInPortal.Remove(portalableObj);
                portalableObj.sittingInPortal = null;
            }
        }
Example #4
0
        public void OnTriggerEnter(Collider other)
        {
            if (other.TaggedAsPlayer())
            {
                return;
            }

            PortalableObject portalableObj = other.gameObject.GetComponent <PortalableObject>();

            if (portalableObj != null)
            {
                objectsInPortal.Add(portalableObj);
                portalableObj.sittingInPortal = this;
            }
        }