Example #1
0
    void OnTriggerEnter(Collider other)
    {
        if (disableTimer > 0)
        {
            return;
        }
        Debug.Log("something hit the portal");

        if (teleportSound != null)
        {
            teleportSound.Play();
        }

        otherPortal.GetComponent <Teleport> ().disableTimer = 1;

        FPCtrl ctrl = other.GetComponent <FPCtrl>();
        RigidbodyFirstPersonController ctrl2 = other.GetComponent <RigidbodyFirstPersonController>();

        if (ctrl != null)
        {
            ctrl.setJumping();
        }
        if (ctrl2 != null)
        {
            ctrl2.setJumping();
        }

        InitReflectionMatrixAndOtherStuff();
        // change position
        other.transform.position = otherPortal.transform.position;        // + otherPortal.transform.forward * 1;
        //other.transform.position = reflection.MultiplyPoint3x4 (other.transform.position);
        other.transform.rotation = ObjectRotation * other.transform.rotation;

        // change velocity
        if (other.GetComponent <Rigidbody> () != null)
        {
            Debug.Log("entering");
            Debug.Log(other.GetComponent <Rigidbody>().velocity);
            //Vector3 velocity = other.GetComponent<Rigidbody> ().velocity;
            //velocity = Vector3.Reflect (velocity, hitNormal);
            Vector3 velocity        = tmpVelocityRotationMatrix.MultiplyPoint(other.GetComponent <Rigidbody>().velocity *SpeedStabilisation);
            Vector3 angularVelocity = tmpVelocityRotationMatrix.MultiplyPoint(other.GetComponent <Rigidbody>().angularVelocity);

            Debug.Log(velocity);

            /*Vector3 tmp = transform.position + velocity;
             * tmp = transform.worldToLocalMatrix.MultiplyPoint (tmp);
             *
             * tmp = otherPortal.transform.localToWorldMatrix.MultiplyPoint (tmp);
             * velocity = tmp - otherPortal.transform.position;
             * velocity = velocity.normalized * other.GetComponent<Rigidbody> ().velocity.magnitude;
             * other.GetComponent<Rigidbody> ().velocity = velocity;
             *
             * other.transform.rotation = Quaternion.LookRotation (tmp - otherPortal.transform.position);*/
            //other.GetComponent<Rigidbody>().velocity = velocity;
            other.GetComponent <Rigidbody>().velocity        = otherPortal.transform.forward.normalized * other.GetComponent <Rigidbody>().velocity.magnitude;
            other.GetComponent <Rigidbody>().angularVelocity = angularVelocity;
        }
    }