示例#1
0
    // Update is called once per frame
    void Update()
    {
        CheckGrab(OVRInput.Controller.LTouch, OVRInput.RawButton.LHandTrigger);
        CheckGrab(OVRInput.Controller.RTouch, OVRInput.RawButton.RHandTrigger);

        if (grabbedByButton != OVRInput.RawButton.None && OVRInput.GetUp(grabbedByButton))
        {
            // release
            grabbedBy       = OVRInput.Controller.None;
            grabbedByButton = OVRInput.RawButton.None;

            float   orbitRadius = (transform.position - Planet.transform.position).magnitude;
            Vector3 axis        = Vector3.Cross(transform.position - Planet.transform.position, transform.position + smoothedGrabVelocity.average - Planet.transform.position);
            orbitRotation = Quaternion.AngleAxis(smoothedGrabVelocity.average.magnitude / (orbitRadius * Time.fixedDeltaTime), axis);
        }

        if (grabbedBy != OVRInput.Controller.None)
        {
            Vector3    oldPosition = transform.position;
            Quaternion oldRotation = transform.rotation;

            Vector3    handPos = OVRManager.instance.transform.LocalToWorld(OVRInput.GetLocalControllerPosition(grabbedBy));
            Quaternion handRot = OVRManager.instance.transform.LocalToWorld(OVRInput.GetLocalControllerRotation(grabbedBy));
            transform.position = handPos + handRot * localGrabOffset;
            transform.rotation = handRot * localGrabRotation;

            spin = transform.rotation * Quaternion.Inverse(oldRotation);

            smoothedGrabVelocity.AddReading(transform.position - oldPosition);
        }
        else if (unfreezeTimestamp != 0 && unfreezeTimestamp < Time.time)
        {
            unfreezeTimestamp = 0;
            float   orbitRadius = (transform.position - Planet.transform.position).magnitude;
            Vector3 axis        = Vector3.Cross(transform.position - Planet.transform.position, transform.position + tractorBeamVelocity - Planet.transform.position);
            orbitRotation = Quaternion.AngleAxis(tractorBeamVelocity.magnitude / (orbitRadius * Time.fixedDeltaTime), axis);
        }
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        CheckGrab(OVRInput.Controller.LTouch, OVRInput.RawButton.LHandTrigger);
        CheckGrab(OVRInput.Controller.RTouch, OVRInput.RawButton.RHandTrigger);

        if (grabbedByButton != OVRInput.RawButton.None && OVRInput.GetUp(grabbedByButton))
        {
            // release
            grabbedBy      = OVRInput.Controller.None;
            rbody.velocity = smoothedVelocity.average / Time.fixedDeltaTime;
        }

        if (grabbedBy != OVRInput.Controller.None)
        {
            Vector3 oldPosition = transform.position;

            Vector3    handPos = OVRManager.instance.transform.LocalToWorld(OVRInput.GetLocalControllerPosition(grabbedBy));
            Quaternion handRot = OVRManager.instance.transform.LocalToWorld(OVRInput.GetLocalControllerRotation(grabbedBy));
            transform.position = handPos + handRot * localGrabOffset;
            transform.rotation = handRot * localGrabRotation;

            smoothedVelocity.AddReading(transform.position - oldPosition);
        }
    }
示例#3
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Vector3 curHandPos = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch);

        handHistory.AddReading(curHandPos);
        Vector3 handPos = handHistory.average;

        smoothedRot = Quaternion.Lerp(smoothedRot, OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch), 0.1f);
        Vector3 forward = (transform.position - handPos).normalized;// smoothedRot * Vector3.forward;
        Vector3 right   = smoothedRot * Vector3.right;
        Vector3 shipUp  = smoothedRot * Vector3.up;

        if (!thrown)
        {
            smoothedVel = Vector3.Lerp(smoothedVel, handPos - transform.position, 0.1f);
        }

        Vector2 stick = OVRInput.Get(OVRInput.RawAxis2D.RThumbstick);

        if (OVRInput.Get(OVRInput.RawButton.B))
        {
            if ((transform.position - handPos).sqrMagnitude < 0.1f * 0.1f)
            {
                transform.position = handPos;
                throwHistory.AddReading(handPos);
                smoothedVel = (handPos - throwHistory.average) * 0.3f;
                thrown      = (throwHistory.average.sqrMagnitude > 0.7f);
            }
            else
            {
                transform.position = handPos + (transform.position - handPos) / 2;
                throwHistory.Clear();
                thrown = false;
            }
        }
        else if (thrown)
        {
            transform.position += smoothedVel;

            if (Mathf.Abs(stick.y) > 0.1f)
            {
                smoothedVel = Quaternion.AngleAxis(stick.y, right) * smoothedVel;
            }
            if (Mathf.Abs(stick.x) > 0.1f)
            {
                smoothedVel = Quaternion.AngleAxis(stick.x, shipUp) * smoothedVel;
            }
        }
        else if (smoothedVel.magnitude > 0.05f)
        {
            transform.position += smoothedVel.normalized * 0.01f;
        }
        //transform.position = Vector3.Lerp(transform.position, handPos, followDist);


        //Vector3 shipForward = forward * stick.y + right * stick.x;


//        if (stick.sqrMagnitude > 0.01f)
//        {
//            transform.position += shipForward * speed;
        transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(smoothedVel, shipUp), 0.1f);
        //        }
        oldHandPos = handPos;
    }