Ejemplo n.º 1
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();
            }
        }
Ejemplo n.º 2
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);
                }
            }
        }