示例#1
0
    void HandleTravellers()
    {
        for (int i = 0; i < trackedTravellers.Count; i++)
        {
            PortalTraveller traveller  = trackedTravellers[i];
            Transform       travellerT = traveller.transform;
            var             m          = linkedPortal.transform.localToWorldMatrix * transform.worldToLocalMatrix * travellerT.localToWorldMatrix;

            Vector3 offsetFromPortal = travellerT.position - transform.position;
            int     portalSide       = System.Math.Sign(Vector3.Dot(offsetFromPortal, transform.forward));
            int     portalSideOld    = System.Math.Sign(Vector3.Dot(traveller.previousOffsetFromPortal, transform.forward));
            // Teleport the traveller if it has crossed from one side of the portal to the other
            if (portalSide != portalSideOld)
            {
                //traveller.GetComponent<Rigidbody>().velocity = linkedPortal.transform.rotation
                //    * (Quaternion.Inverse(transform.rotation)
                //    * traveller.GetComponent<Rigidbody>().velocity);



                //Physics.gravity = linkedPortal.transform.rotation * GM.initialGrav;
                //GM.Dir = linkedPortal.directionIndex;
                //Physics.gravity = transform.rotation * Physics.gravity;
                var positionOld = travellerT.position;
                var rotOld      = travellerT.rotation;
                traveller.Teleport(transform, linkedPortal.transform, m.GetColumn(3), m.rotation);
                traveller.graphicsClone.transform.SetPositionAndRotation(positionOld, rotOld);
                // Can't rely on OnTriggerEnter/Exit to be called next frame since it depends on when FixedUpdate runs
                if (traveller.gameObject.layer == 9 || traveller.gameObject.layer == 10)
                {
                    if (traveller.gameObject.layer == 9)
                    {
                        Physics.gravity = travellerT.rotation * GM.initialGrav;
                    }

                    traveller.GetComponent <Rigidbody>().velocity = travellerT.rotation
                                                                    * (Quaternion.Inverse(rotOld)
                                                                       * traveller.GetComponent <Rigidbody>().velocity);
                }



                linkedPortal.OnTravellerEnterPortal(traveller);
                trackedTravellers.RemoveAt(i);
                i--;
            }
            else
            {
                //Physics.gravity = linkedPortal.transform.rotation * Physics.gravity;
                traveller.graphicsClone.transform.SetPositionAndRotation(m.GetColumn(3), m.rotation);
                //UpdateSliceParams (traveller);
                traveller.previousOffsetFromPortal = offsetFromPortal;
            }
        }
    }
示例#2
0
    void HandleTravellers()
    {
        for (int i = 0; i < trackedTravellers.Count; i++)
        {
            PortalTraveller traveller  = trackedTravellers[i];
            Transform       travellerT = traveller.transform;
            var             m          = linkedPortal.transform.localToWorldMatrix * transform.worldToLocalMatrix * travellerT.localToWorldMatrix;

            Vector3 offsetFromPortal = travellerT.position - transform.position;
            int     portalSide       = System.Math.Sign(Vector3.Dot(offsetFromPortal, transform.forward));
            int     portalSideOld    = System.Math.Sign(Vector3.Dot(traveller.previousOffsetFromPortal, transform.forward));
            // Teleport the traveller if it has crossed from one side of the portal to the other
            if (portalSide != portalSideOld)
            {
                var positionOld = travellerT.position;
                var rotOld      = travellerT.rotation;
                traveller.Teleport(transform, linkedPortal.transform, m.GetColumn(3), m.rotation);
                traveller.graphicsClone.transform.SetPositionAndRotation(positionOld, rotOld);
                // Can't rely on OnTriggerEnter/Exit to be called next frame since it depends on when FixedUpdate runs
                linkedPortal.OnTravellerEnterPortal(traveller);
                trackedTravellers.RemoveAt(i);
                if (embeddedWall != null)
                {
                    Physics.IgnoreCollision(traveller.GetComponent <Collider>(), embeddedWall, false);
                }
                i--;
            }
            else
            {
                traveller.graphicsClone.transform.SetPositionAndRotation(m.GetColumn(3), m.rotation);
                //UpdateSliceParams (traveller);
                traveller.previousOffsetFromPortal = offsetFromPortal;
            }
        }
    }
示例#3
0
    void OnTravellerEnterPortal(PortalTraveller traveller)
    {
        if (!trackedTravellers.Contains(traveller))
        {
            traveller.EnterPortalThreshold();
            traveller.previousOffsetFromPortal = traveller.transform.position - transform.position;
            trackedTravellers.Add(traveller);

            Physics.IgnoreCollision(traveller.GetComponent <Collider>(), embeddedWall, true);
        }
    }
示例#4
0
    void HandleTravellers()
    {
        for (int i = 0; i < trackedTravellers.Count; i++)
        {
            PortalTraveller traveller = trackedTravellers[i];
            if (traveller == null) // debugdestroy
            {
                continue;
            }

            if (traveller.GraphicsObject2 == null) // model 2 not here
            {
                Transform travellerT = traveller.transform;
                Transform model1T    = traveller.GraphicsObject.transform;
                var       t          = linkedPortal.transform.localToWorldMatrix * transform.worldToLocalMatrix * travellerT.localToWorldMatrix;
                var       m1         = linkedPortal.transform.localToWorldMatrix * transform.worldToLocalMatrix * model1T.localToWorldMatrix;

                Vector3 offsetFromPortal = travellerT.position - transform.position;
                int     portalSide       = System.Math.Sign(Vector3.Dot(offsetFromPortal, transform.forward));
                int     portalSideOld    = System.Math.Sign(Vector3.Dot(traveller.PreviousOffsetFromPortal, transform.forward));
                // Teleport the traveller if it has crossed from one side of the portal to the other
                if (portalSide != portalSideOld)
                {
                    var positionOld = model1T.position;
                    var rotOld      = model1T.rotation;
                    if (traveller.GetComponent <PhysicsObject>())
                    {
                        traveller.GetComponent <PhysicsObject>().Drop();

                        /*if (traveller.GetComponent<PhysicsObject>().m_Held)
                         * {
                         *  GameObject mtraveller = traveller.GetComponent<PhysicsObject>().playercontroller.GetComponent<FPSWeapon>().m_HandTransform.gameObject;
                         *  Transform mtravellerT = mtraveller.transform;
                         *  var mt = linkedPortal.transform.localToWorldMatrix * transform.worldToLocalMatrix * mtravellerT.localToWorldMatrix;
                         *
                         *  var mpositionOld = model1T.position;
                         *  var mrotOld = model1T.rotation;
                         *
                         *  traveller.Teleport(transform, linkedPortal.transform, mt.GetColumn(3), mt.rotation);
                         *  traveller.GraphicsClone.transform.SetPositionAndRotation(mpositionOld, mrotOld);
                         * }*/
                    }

                    /*else
                     * {
                     *  traveller.Teleport(transform, linkedPortal.transform, t.GetColumn(3), t.rotation);
                     *  traveller.GraphicsClone.transform.SetPositionAndRotation(positionOld, rotOld);
                     * }*/
                    traveller.Teleport(transform, linkedPortal.transform, t.GetColumn(3), t.rotation);
                    traveller.GraphicsClone.transform.SetPositionAndRotation(positionOld, rotOld);
                    // Can't rely on OnTriggerEnter/Exit to be called next frame since it depends on when FixedUpdate runs
                    linkedPortal.OnTravellerEnterPortal(traveller);
                    trackedTravellers.RemoveAt(i);
                    i--;
                }
                else
                {
                    traveller.GraphicsClone.transform.SetPositionAndRotation(m1.GetColumn(3), m1.rotation);
                    traveller.PreviousOffsetFromPortal = offsetFromPortal;
                }
            }
            else   // model 2 is here
            {
                Transform travellerT = traveller.transform;
                Transform model1T    = traveller.GraphicsObject.transform;
                Transform model2T    = traveller.GraphicsObject2.transform;
                var       t          = linkedPortal.transform.localToWorldMatrix * transform.worldToLocalMatrix * travellerT.localToWorldMatrix;
                var       m1         = linkedPortal.transform.localToWorldMatrix * transform.worldToLocalMatrix * model1T.localToWorldMatrix;
                var       m2         = linkedPortal.transform.localToWorldMatrix * transform.worldToLocalMatrix * model2T.localToWorldMatrix;

                Vector3 offsetFromPortal = travellerT.position - transform.position;
                int     portalSide       = System.Math.Sign(Vector3.Dot(offsetFromPortal, transform.forward));
                int     portalSideOld    = System.Math.Sign(Vector3.Dot(traveller.PreviousOffsetFromPortal, transform.forward));
                // Teleport the traveller if it has crossed from one side of the portal to the other
                if (portalSide != portalSideOld)
                {
                    var positionOld  = model1T.position;
                    var rotOld       = model1T.rotation;
                    var positionOld2 = model2T.position;
                    var rotOld2      = model2T.rotation;
                    if (traveller.GetComponent <PhysicsObject>())
                    {
                        traveller.GetComponent <PhysicsObject>().Drop();
                    }
                    traveller.Teleport(transform, linkedPortal.transform, t.GetColumn(3), t.rotation);
                    traveller.GraphicsClone.transform.SetPositionAndRotation(positionOld, rotOld);
                    traveller.GraphicsClone2.transform.SetPositionAndRotation(positionOld2, rotOld2);
                    // Can't rely on OnTriggerEnter/Exit to be called next frame since it depends on when FixedUpdate runs
                    linkedPortal.OnTravellerEnterPortal(traveller);
                    trackedTravellers.RemoveAt(i);
                    i--;
                }
                else
                {
                    traveller.GraphicsClone.transform.SetPositionAndRotation(m1.GetColumn(3), m1.rotation);
                    traveller.GraphicsClone2.transform.SetPositionAndRotation(m2.GetColumn(3), m2.rotation);
                    traveller.PreviousOffsetFromPortal = offsetFromPortal;
                }
            }
        }
    }