Ejemplo n.º 1
0
    private void FixedUpdate()
    {
        float x = Input.GetAxis("Horizontal") * speed * rate;
        float z = Input.GetAxis("Vertical") * speed * rate;

        Transform t = VRMode ? vr.CameraTransform : transform;
        Vector3   f = t.forward;

        f.y = 0;
        Vector3 r = t.right;

        r.y = 0;

        Vector3 tmp = transform.localPosition;
        Vector3 dir = f * z + r * x;

        tmp.x += dir.x;
        tmp.y += dir.y;
        tmp.z += dir.z;
        transform.localPosition = tmp;

        if (VRMode)
        {
            bool noInput = x == 0 && z == 0;
            if (!noInput)
            {
                transform.rotation = Quaternion.AngleAxis(Ultility.AbsolutelyAngle(dir), Vector3.up);
            }

            if (Input.GetButtonDown("Teleport"))
            {
                vr.Teleport(transform.position, transform.forward);
            }

            if (Input.GetButtonDown("Resume"))
            {
                Vector3 pos = vr.Camera.transform.position;
                pos.y = vr.transform.position.y + vr.Height;
                transform.position = pos;

                Vector3 rot = vr.Camera.transform.rotation.eulerAngles;
                rot.x = rot.z = 0f;
                transform.eulerAngles = rot;
            }
        }
        else
        {
            float y = Input.GetAxis("Horizontal2");
            transform.rotation = transform.rotation * Quaternion.AngleAxis(y, Vector3.up);

            float head = Input.GetAxis("Vertical2");
            CameraBase.transform.localRotation = CameraBase.transform.localRotation * Quaternion.Euler(head, 0, 0);
        }
    }
Ejemplo n.º 2
0
    private void Start()
    {
        VRProxy.OnVRTeleport += () =>
        {
            Vector3 pos = VRCamera.transform.position;
            pos.y = transform.position.y + PlayerHeight;
            Player.transform.position = pos;

            float cameraAngle = Ultility.AbsolutelyAngle(VRCamera.transform.forward);
            Player.transform.rotation = Quaternion.AngleAxis(cameraAngle, Vector3.up);
        };
    }
Ejemplo n.º 3
0
    public void Teleport(Vector3 pos, Vector3 forward)
    {
        float playerAngle = Ultility.AbsolutelyAngle(forward);
        float cameraAngle = Ultility.AbsolutelyAngle(VRCamera.transform.forward);
        float baseAngle   = Ultility.AbsolutelyAngle(transform.forward);

        //transform.rotation = Quaternion.AngleAxis(baseAngle + playerAngle - cameraAngle, Vector3.up);

        Vector3 diff = pos - VRCamera.transform.position;

        diff.y              = 0f;
        transform.position += diff;
    }