Example #1
0
        void OnTriggerStay(Collider col)
        {
            if (device != null && device.GetPressDown(SteamVR_Controller.ButtonMask.Grip) && currentObject == null)
            {
                if (col.CompareTag("Grabbable"))
                {
                    objWasKinematic = col.attachedRigidbody.isKinematic;
                    col.attachedRigidbody.isKinematic = true;
                    //FixedJoint grabberJoint = col.gameObject.AddComponent<FixedJoint>();
                    //grabberJoint.connectedBody = gameObject.GetComponent<Rigidbody>();
                    currentObject = col.gameObject;

                    Teleportable teleportable2 = col.GetComponent <Teleportable>();


                    if (teleportable2)
                    {
                        teleportable2.root.SetParent(transform);
                        teleportable2.VisOnly = true;
                        teleportable2.IgnoreCollision(col);
                    }
                    else
                    {
                        currentObject.transform.SetParent(transform);
                        teleportable.IgnoreCollision(col);
                    }


                    //teleportable2.isActive = false;
                    //teleportable.AddChild(currentObject);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Removes primed objects from the queue if they move away from the portal
        /// </summary>
        public void E_OnTriggerExit(Collider col)
        {
            Teleportable teleportScript = col.GetComponent <Teleportable>();

            if (col == headCollider)
            {
                _headInPortalTrigger = false;
            }
            RemoveTeleportable(teleportScript);
        }
Example #3
0
 private void RemoveTeleportable(Teleportable teleportScript)
 {
     if (teleportScript && _nearTeleportables.Contains(teleportScript))
     {
         teleportScript.ResetDoppleganger();
         if (!nonObliqueOverride)
         {
             teleportScript.SetClipPlane(Vector3.zero, Vector3.zero, teleportScript.oTeleportRends);
         }
         _nearTeleportables.Remove(teleportScript);
         teleportScript.LeavePortal();
         teleportScript.ResumeAllCollision();
     }
 }
Example #4
0
        /// <summary>
        /// Attempt to add a teleportableScript to the nearteleportables group
        /// </summary>
        /// <param name="teleportScript">the script to add</param>
        private void AddTeleportable(Teleportable teleportScript)
        {
            if (teleportScript && !_nearTeleportables.Contains(teleportScript))
            {
                teleportScript.doppleganger.SetActive(true);

                _nearTeleportables.Add(teleportScript);

                //Ignores collision with rear objects- todo: add buffer around portal
                Vector3[] checkedVerts = PortalUtils.ReferenceVerts(_meshFilter.mesh);

                //Ignore collision with the portal itself
                teleportScript.IgnoreCollision(_collider);
                teleportScript.IgnoreCollision(targetPortal._collider);

                //Ignores rear-facing colliders
                Ray          ray;
                RaycastHit[] hit;
                for (int i = 0; i < checkedVerts.Length; i++)
                {
                    ray = new Ray(transform.TransformPoint(checkedVerts[i]) + transform.forward * 0.01f, -transform.forward);
                    hit = Physics.RaycastAll(ray, 1 * transform.parent.localScale.z, ~0, QueryTriggerInteraction.Collide);
                    Debug.DrawRay(ray.origin, -transform.forward * transform.parent.localScale.z, Color.cyan, 10);
                    if (hit.Length > 0)
                    {
                        foreach (RaycastHit h in hit)
                        {
                            //Never ignore collisions with teleportables
                            //Never ignore collisions with teleportables
                            if (h.collider.gameObject.tag != "PhysicsPassthroughDuplicate" &&
                                h.collider.gameObject.GetComponent <Teleportable>() == null)
                            {
                                if (h.collider.transform.parent && transform.parent && h.collider.transform.parent.parent && transform.parent.parent)
                                {
                                    if (h.collider.transform.parent.parent != transform.parent.parent)
                                    {
                                        teleportScript.IgnoreCollision(h.collider);
                                    }
                                }
                                else
                                {
                                    teleportScript.IgnoreCollision(h.collider);
                                }
                            }
                        }
                    }
                }
                UpdateDopplegangers();
            }
        }
Example #5
0
        public void Initialize(Teleportable teleportable)
        {
            this.teleportable = teleportable;
            originalParent    = transform.parent;
            try {
                otherTransform       = PortalUtils.FindAnalogousTransform(transform, teleportable.root, teleportable.doppleganger.transform, true);
                otherTransformParent = otherTransform.parent;
            } catch (System.NullReferenceException e) {
                Debug.LogError("Teleportablescript on " + name + "had a problem:" + e.Message);
            }

            originalPosition = transform.localPosition;
            originalRotation = transform.localRotation;
            originalScale    = transform.localScale;
        }
Example #6
0
        protected override void OnPassthrough()
        {
            if (currentObject)
            {
                Teleportable teleportable2 = currentObject.GetComponent <Teleportable>();
                if (teleportable2)
                {
                    teleportable2.UpdateDoppleganger();

                    /*
                     * Vector3 oldPos = currentObject.transform.localPosition;
                     * Rigidbody rigidbody = currentObject.GetComponent<Rigidbody>();
                     * rigidbody.position = transform.TransformPoint(oldPos);*/
                }
            }
        }
Example #7
0
        // Update is called once per frame
        new void Update()
        {
            try {
                device = SteamVR_Controller.Input((int)trackedObj.index);
            } catch (System.IndexOutOfRangeException) {
                return;
            }
            velocity     = (transform.position - lastPosition) / Time.deltaTime;
            lastPosition = transform.position;
            //Adds velocity to the queue
            avgVelocitySamples.Enqueue(velocity);
            if (avgVelocitySamples.Count > sampleframes)
            {
                avgVelocitySamples.Dequeue();
            }



            if (currentObject != null)
            {
                Teleportable teleportable2 = currentObject.GetComponent <Teleportable>();
                //Initially use other teleporter for early detection, then switch once grabber is through portal

                //teleportable2.enabled = !throughPortal;
                if (!device.GetPress(SteamVR_Controller.ButtonMask.Grip) || currentObject.tag != "Grabbable")
                {
                    //Resumes teleportable
                    if (teleportable2)
                    {
                        teleportable2.VisOnly  = false;
                        teleportable2.isActive = true;
                    }
                    //Removes rigidbody from player and doppleganger


                    if (!throughPortal)
                    {
                    }
                    //teleportable.RemoveChild(currentObject);
                    else
                    {
                        Vector3   oldPosition = currentObject.transform.position;
                        Transform oldParent   = currentObject.transform.parent;
                        if (teleportable2)
                        {
                            teleportable2.root.SetParent(transform);
                        }
                        //Reparents the doppleganger component to where it should be
                        //PortalUtils.FindAnalogousTransform(currentObject.transform, teleportable.doppleganger.transform, teleportable.root, false).SetParent(oldParent);
                        //teleportable.RemoveChild(currentObject);
                        currentObject.transform.position = oldPosition;
                    }
                    //Resumes Rigidbody
                    if (teleportable2)
                    {
                        if (teleportable2.root.parent == transform)
                        {
                            teleportable2.root.SetParent(null);
                        }
                    }
                    else
                    {
                        if (currentObject.transform.parent == transform)
                        {
                            currentObject.transform.SetParent(null);
                        }
                    }
                    Rigidbody currentRigid = currentObject.GetComponent <Collider>().attachedRigidbody;
                    currentRigid.isKinematic     = objWasKinematic;
                    currentRigid.velocity        = velocity;
                    currentRigid.angularVelocity = device.angularVelocity;
                    teleportable.AddCollision(currentObject.GetComponent <Collider>());
                    currentObject = null;
                    return;
                }
                else
                {
                    teleportable.IgnoreCollision(currentObject.GetComponent <Collider>());
                }
            }
            base.Update();
        }
Example #8
0
        IEnumerator Setup()
        {
            yield return(new WaitForEndOfFrame());

            while (targetInitializer == null)
            {
                yield return(new WaitForEndOfFrame());
            }
            //Removes the impostor, if there was one
            gameObject.GetComponent <MeshRenderer>().enabled = false;
            portal.SetActive(true);
            //Sets up portal camera script
            portalCameraScript = transform.FindChild("Portal/PortalCameraParent/PortalCamera").GetComponent <PortalCamera>();
            portalScript       = transform.FindChild("Portal/PortalRenderer/BackWall").GetComponent <Portal>();
            portalTrigger      = transform.FindChild("Portal/PortalRenderer/PortalTrigger").GetComponent <PortalTrigger>();
            //VR functionality
            if (VR_Enabled)
            {
                //Scans for VR player teleport objects
                try {
                    playerTeleportable = GameObject.Find("PlayerExtents").GetComponent <Teleportable>();
                    portalScript.playerTeleportable = playerTeleportable;
                } catch (System.NullReferenceException) {
                    Debug.LogWarning("No VR rig collider found! Player will not be able to walk into portals.");
                }
            }
            else
            {
                //Non-VR functionality
            }

            portalCameraScript.PortalCameraParent = portalCameraScript.gameObject.transform.parent.gameObject.transform;
            portalCameraScript.portalTransform    = transform.FindChild("Portal/PortalSource").transform;
            portalCameraScript.portalDestination  = targetInitializer.transform.FindChild("Portal/PortalTarget");


            portalPlaceholder = transform.FindChild("Portal/PortalRenderer/PortalPlaceholder").gameObject;

            portalScript.origin             = transform.FindChild("Portal/PortalSource");
            portalScript.destination        = targetInitializer.transform.FindChild("Portal/PortalTarget");
            portalScript.targetPortal       = targetInitializer.transform.FindChild("Portal/PortalRenderer/BackWall").GetComponent <Portal>();
            portalScript.portalRoot         = transform;
            portalScript.VR                 = VR_Enabled;
            portalScript.is3d               = is3d;
            portalScript.mask               = mask;
            portalScript.nonObliqueOverride = NonObliqueOverride;
            portalScript.inverted           = inverted;
            portalScript.optimize           = optimize;
            portalScript.portalCamera       = portalCameraScript;
            portalScript.physicsPassthrough = transform.FindChild("Portal/PortalRenderer/PortalPhysicsPassthrough").GetComponent <PhysicsPassthrough>();
            portalScript.enterable          = enterable;
            portalScript.placeholder        = portalPlaceholder;

            portalTrigger.portal = portalScript.gameObject;

            //Readies the portal for scaling and transformations
            portalRenderer = transform.FindChild("Portal/PortalRenderer/").gameObject;

            portalPlaceholder.GetComponent <Renderer>().material.SetTexture("_AlphaTexture", mask);
            portalOrigin      = transform.FindChild("Portal/PortalSource");
            portalDestination = transform.FindChild("Portal/PortalTarget");

            //Enable scripts
            portalScript.enabled       = true;
            portalCameraScript.enabled = true;
            portalTrigger.enabled      = true;
            setup = true;

            //Transfer transform values to modifiable var
            PortalOpeningSize    = transform.localScale;
            transform.localScale = Vector3.one;

            targetInitializer.GetComponent <PortalController>().color = color;
        }
Example #9
0
        /// <summary>
        /// Checks if objects are in portal, and teleports them if they are. Also handles player entry.
        /// </summary>
        /// <param name="col"></param>
        public void E_OnTriggerStay(Collider col)
        {
            Teleportable teleportScript = col.GetComponent <Teleportable>();

            AddTeleportable(teleportScript);
            //Detects when head enters portal area
            if (col == headCollider)
            {
                _headInPortalTrigger = true;
            }

            if (enterable && teleportScript)
            {
                //Updates clip planes for disappearing effect
                if (!nonObliqueOverride)
                {
                    teleportScript.SetClipPlane(origin.position, origin.forward, teleportScript.oTeleportRends);
                    teleportScript.SetClipPlane(destination.position, -destination.forward, teleportScript.dTeleportRends);
                }
                if (GlobalPortalSettings.physicsPassthrough)
                {
                    //Makes objects collide with objects on the other side of the portal
                    foreach (Tuple <Collider, Collider> c in passthroughColliders)
                    {
                        teleportScript.AddCollision(c.Item2);
                    }

                    foreach (Collider c in bufferWall)
                    {
                        teleportScript.AddCollision(c);
                    }
                }


                //Passes portal info to teleport script
                teleportScript.SetPortalInfo(this);

                //Teleports objects
                if (PortalUtils.IsBehind(col.transform.position, origin.position, origin.forward) && !teleportScript.VisOnly)
                {
                    //_nearTeleportables.Remove(teleportScript);
                    //teleportScript.ResumeAllCollision();
                    RemoveTeleportable(teleportScript);
                    PortalUtils.TeleportObject(teleportScript.root.gameObject, origin, destination, teleportScript.root);
                    targetPortal.FixedUpdate();
                    targetPortal.SendMessage("E_OnTriggerStay", col);
                    teleportScript.Teleport();
                    targetPortal.UpdateDopplegangers();
                    targetPortal.physicsPassthrough.SendMessage("UpdatePhysics");
                    //physicsPassthrough.SendMessage("UpdatePhysics");

                    if (teleportScript == playerTeleportable)
                    {
                        targetPortal.UpdateDopplegangers();
                        targetPortal.IncomingCamera();
                        _CheeseActivated     = false;
                        _headInPortalTrigger = false;
                        //Resets the vis depth of the portal volume
                        if (!is3d)
                        {
                            transform.localScale = new Vector3(1f, 1f, 0f);
                        }

                        //Flips the nearby light tables

                        ArrayList tempList = new ArrayList(passthroughLights);
                        passthroughLights = targetPortal.passthroughLights;
                        targetPortal.passthroughLights = tempList;
                        foreach (Tuple <Light, GameObject> tup in passthroughLights)
                        {
                            tup.Item2.transform.parent = destination;
                        }
                        foreach (Tuple <Light, GameObject> tup in targetPortal.passthroughLights)
                        {
                            tup.Item2.transform.parent = targetPortal.destination;
                        }
                    }
                }
            }
        }
Example #10
0
        /// <summary>
        /// All collsision methods are externed to another script
        /// </summary>
        public void E_OnTriggerEnter(Collider col)
        {
            Teleportable teleportScript = col.GetComponent <Teleportable>();

            AddTeleportable(teleportScript);
        }