//checks magnitude of the acceleromter value - detecting any shake
 public void movementCheck(Vector3 accelerometerCurrentVal)
 {
     currentDeviceRotation = DeviceRotation.GetRotation().eulerAngles;
     if (keepStillTriggered)
     {
         if (accelerometerCurrentVal.magnitude > 1f || hasRotationChanged(currentDeviceRotation) || thirdPersonUserControl.GetMoveMagnitude() > 0)
         {
             witchPromptText.text = "YOU MOVED - GAME OVER";
             isStill = false;
         }
     }
 }
예제 #2
0
    public void BeginBalance(Transform thisEnd, Transform otherEnd)
    {
        print("Begin balance");

        isBalancing = true;
        _dial.SetActive(true);

        _character.transform.position = thisEnd.position;
        _character.transform.LookAt(otherEnd);
        _moveTowards = otherEnd.position;

        _enterZAngle = DeviceRotation.GetRotation().eulerAngles.z;
        // _negatePhoneRotation = Quaternion.Inverse(DeviceRotation.GetRotation());

        GlobalGameManager.Instance.ToggleUI(false);
    }
예제 #3
0
    private float BalanceAngleDifference()
    {
        // What is the z angle of the phone?
        _currentZAngle = DeviceRotation.GetRotation().eulerAngles.z;
        // How different is it to the entry z angle?
        var difference = _enterZAngle - _currentZAngle;

        // A bit of normalisation
        if (difference > 180)
        {
            difference -= 360f;
        }

        // Return the inverse as otherwise the UI rotation is counter intuitive (it's the opposite)
        return(difference * -1);
    }
예제 #4
0
    private void MoveCheck()
    {
        float xAngle = 0f;
        float yAngle = 0f;

        if (ControlsManager.Instance.CurrentMobileControls == MobileControls.Gyroscope)
        {
            Vector3 referenceRotation = DeviceRotation.ReferenceOrientation * Vector3.forward;
            Vector3 currentRotation   = DeviceRotation.GetRotation() * Vector3.forward;

            xAngle = -Vector3.SignedAngle(referenceRotation, currentRotation, Vector3.forward);
            yAngle = -Vector3.SignedAngle(referenceRotation, currentRotation, Vector3.right);

            if (Mathf.Abs(xAngle) > xMinMoveAngle)
            {
                xAngle /= xMaxMoveAngle;
            }
            else
            {
                xAngle = 0f;
            }

            if (Mathf.Abs(yAngle) > yMinMoveAngle)
            {
                yAngle /= yMaxMoveAngle;
            }
            else
            {
                yAngle = 0f;
            }
        }

        Vector2 joystickDir = joystick.Direction;
        float   rawX        = Input.GetAxisRaw("Horizontal") + joystickDir.x + xAngle;
        float   rawY        = Input.GetAxisRaw("Vertical") + joystickDir.y + yAngle;

        Vector2 rawMove        = new Vector2(rawX, rawY);
        Vector2 normalizedMove = rawMove.sqrMagnitude > 1f ? rawMove.normalized : rawMove;

        float smoothing = moveSmoothing * Time.deltaTime;

        Move = Vector2.Lerp(Move, normalizedMove, smoothing);
    }
    //timer for 10 seconds
    public IEnumerator KeepStillTime()
    {
        //guard boolean to make sure the movementCheck is only relevant for these 10 seconds
        keepStillTriggered    = true;
        initialDeviceRotation = DeviceRotation.GetRotation().eulerAngles;

        // Notify the AI that they need to run away and whatnot
        if (witchArriveEvent != null)
        {
            witchArriveEvent();
        }

        for (int i = (int)keepStillDuration; i >= 1; i--)
        {
            //if we moved, stop the timer
            if (!isStill)
            {
                yield return(new WaitForSecondsRealtime(2.5f));

                loadLevelScript.LoadSavedLevel(true);
                break;
            }

            yield return(new WaitForSecondsRealtime(1));
        }
        keepStillTriggered = false;

        //if we stayed still for the full time, prompt user and then clear text
        if (isStill)
        {
            witchPromptText.text = "WELL DONE!";

            yield return(new WaitForSecondsRealtime(1));
        }

        witchPromptText.text = " ";
        if (witchLeaveEvent != null)
        {
            witchLeaveEvent();
        }
        reset();
    }
예제 #6
0
파일: Portal.cs 프로젝트: Jackahashi/ARkit
    //-----------------------------------------------------------------------------------------

    // returns the z axis rotation

    float GetAngleByDeviceAxis(Vector3 axis)
    {
        Quaternion deviceRotation      = DeviceRotation.GetRotation();
        Quaternion eliminationOfOthers = Quaternion.Inverse(
            Quaternion.FromToRotation(axis, deviceRotation * axis)
            );
        Vector3 filteredEuler = (eliminationOfOthers * deviceRotation).eulerAngles;

        float result = filteredEuler.z;

        if (axis == Vector3.up)
        {
            result = filteredEuler.y;
        }
        if (axis == Vector3.right)
        {
            // incorporate different euler representations.
            result = (filteredEuler.y > 90 && filteredEuler.y < 270) ? 180 - filteredEuler.x : filteredEuler.x;
        }
        return(result);
    }
        /// <summary>
        /// This rotates the camera to match the orientation of the phone
        /// </summary>
        public void TiltPhone()
        {
            // Helps to stop us getting caught in a bad change of states. Resets in ResetRotation().
            if (!tilting)
            {
                // Save our current rotation before doing anything else. This is where we'll return later.
                _resetRotation = transform.localRotation;
                // This is the opposite of the phones rotation when entering the tilt mode.
                // We are aiming to negate by this value later.
                _negatePhoneRotation = Quaternion.Inverse(DeviceRotation.GetRotation());
                tilting = true;
                //debugText.enabled = true;
            }

            // None! This is 1 rotation offest by another. No idea how it works.
            // Why do you offset the right by the left? Who knows. It's magic.
            _desiredRotation = _negatePhoneRotation * DeviceRotation.GetRotation();

            // Set rotation at the end, assumes _desiredRotation has been set in 1 of the above if statements.
            transform.localRotation = _desiredRotation;
            // Cache it back into the conveniently shorter variable name.
            _currentRotation = transform.localRotation;
            //debugText.text = _desiredRotation.ToString();
        }