Example #1
0
    void JoyconUpdate()
    {
        stick = j.GetStick();

        // Gyro values: x, y, z axis values (in radians per second)
        gyro = j.GetGyro();

        // Accel values:  x, y, z axis values (in Gs)
        accel = j.GetAccel();

        gravity.x = 0.9f * gravity.x + 0.1f * accel.x;
        gravity.y = 0.9f * gravity.y + 0.1f * accel.y;
        gravity.z = 0.9f * gravity.z + 0.1f * accel.z;

        linearAccel.x = accel.x - gravity.x;
        linearAccel.y = accel.y - gravity.y;
        linearAccel.z = accel.z - gravity.z;


        orientation.x = j.GetVector().x;
        orientation.y = j.GetVector().y;
        orientation.w = j.GetVector().w;

        //Al sumarle la y a la z el gameObject se coloca en la posición que tiene el mando. Actúan sobre el mismo eje de forma contraria
        orientation.z = j.GetVector().z + j.GetVector().y;

        gameObject.transform.rotation = orientation;
    }
Example #2
0
    private void Update()
    {
        m_pressedButtonL = null;
        m_pressedButtonR = null;

        if (m_joycons == null || m_joycons.Count <= 0) return;

        //foreach (var button in m_buttons)
        //{
        //    if (m_joyconL.GetButton(button))
        //    {
        //        m_pressedButtonL = button;
        //    }
        //    if (m_joyconR.GetButton(button))
        //    {
        //        m_pressedButtonR = button;
        //    }
        //}

        if (Input.GetKeyDown(KeyCode.Z))
        {
            m_joyconL.SetRumble(160, 320, 0.6f, 200);
        }
        if (Input.GetKeyDown(KeyCode.X))
        {
            m_joyconR.SetRumble(160, 320, 0.6f, 200);
        }

        if(m_joyconR.GetButton(Joycon.Button.SHOULDER_2))
        {
            gameObject.transform.Translate(0, 0, 0.08f);
        }

        obj.transform.localRotation = new Quaternion(0, -m_joyconL.GetVector().z, 0, m_joyconL.GetVector().w);
    }
Example #3
0
    void SetKeys(ref Keys key, Joycon joycon)
    {
        key.JoyStick.x = joycon.GetStick()[0];
        key.JoyStick.y = joycon.GetStick()[1];
        key.JoyGyro    = joycon.GetGyro();
        key.JoyAccel   = joycon.GetAccel();
        key.JoyRad     = joycon.GetVector();


        Vector3 gy = key.JoyGyro;

        gy.x        = -key.JoyGyro.y;
        gy.z        = -key.JoyGyro.x;
        gy.y        = key.JoyGyro.z;
        key.JoyGyro = gy;

        Vector3 ac = key.JoyGyro;

        ac.x         = -key.JoyAccel.y;
        ac.z         = -key.JoyAccel.x;
        ac.y         = 0f;//key.JoyAccel.z;
        key.JoyAccel = ac;

        //なぜか↑のほうむくから補正
        key.JoyGyro.x += 0.01f;
    }
Example #4
0
    // Update is called once per frame
    void Update()
    {
        if (j != null && j.state > Joycon.state_.ATTACHED)
        {
            gyro = j.GetGyro();

            // Accel values:  x, y, z axis values (in Gs)
            accel = j.GetAccel();

            orientation = j.GetVector();

            gameObject.transform.rotation = orientation;

            if (this.transform.rotation.eulerAngles.y - 90 < maxAngle && this.transform.rotation.eulerAngles.y - 90 > -maxAngle)
            {
                xMax = this.transform.rotation.eulerAngles.y - 90;
            }

            if (-this.transform.rotation.eulerAngles.z + 90 < maxAngle && -this.transform.rotation.eulerAngles.z + 90 > -maxAngle)
            {
                zMax = -this.transform.rotation.eulerAngles.z + 90;
            }

            if (this.transform.rotation.eulerAngles.x < maxAngle && -this.transform.rotation.eulerAngles.x > maxAngle)
            {
                yMax = this.transform.rotation.eulerAngles.x;
            }

            fix = Quaternion.Euler(xMax, yMax, zMax);
            gameObject.transform.rotation = fix;
        }
    }
Example #5
0
    protected void UpdateHandRotation()
    {
        // make sure the Joycon only gets checked if attached
        if (joycons.Count > 0)
        {
            currentJoycon = joycons [jc_ind];

            //	j.SetRumble (160, 320, 0.2f, 200);
            // Then call SetRumble(0,0,0) when you want to turn it off.

            stick = currentJoycon.GetStick();

            // Gyro values: x, y, z axis values (in radians per second)
            gyro = currentJoycon.GetGyro();

            // Accel values:  x, y, z axis values (in Gs)
            accel = currentJoycon.GetAccel();

            orientation = currentJoycon.GetVector();

            //Vector3 v = orientation.eulerAngles;

            gameObject.transform.rotation = orientation;
            //SetRotation();

            eulerAngle = orientation.eulerAngles;
        }
    }
Example #6
0
 public void SetRotation()
 {
     // gameObject.transform.rotation=currentJoycon.GetVector()*Quaternion.Inverse(transform.parent.GetComponent<CharacterManager>().GetRotation());
     // gameObject.transform.rotation= transform.parent.GetComponent<CharacterManager>().GetRotation()*Quaternion.Inverse( currentJoycon.GetVector());
     gameObject.transform.rotation = currentJoycon.GetVector() * transform.parent.GetComponent <CharacterManager>().GetRotation();
     // gameObject.transform.rotation.SetEulerRotation
 }
Example #7
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (joycons.Count > 0)
        {
            if (Input.GetButtonDown("Fire2"))
            {
                transform.rotation = joycons[jc_ind].GetVector();
            }

            Joycon j = joycons[jc_ind];

            accel          = j.GetAccel();
            accelMagnitude = accel.magnitude;

            orientation = j.GetVector();
            body.MoveRotation(orientation);
        }
        else
        {
            float xRot = Input.GetAxis("Horizontal");
            float yRot = Input.GetAxis("Vertical");
            //float zRot = Input.GetAxis("Yaw");

            //rotDir = new Vector3(xRot, yRot, zRot).normalized;

            //body.MoveRotation(body.rotation * Quaternion.Euler(rotDir * rotSpeed));

            Quaternion deltaRotation = Quaternion.AngleAxis(xRot * rotSpeed, Vector3.down) * Quaternion.AngleAxis(yRot * rotSpeed, Vector3.right);

            body.MoveRotation(deltaRotation.normalized * transform.rotation);
        }
    }
        public static void UpdateJoyconRotation(object o)
        {
            JoyconManager.Instance.Update();

            var pkt = EncodeQuaternion(jc.GetVector());

            processPacket.Invoke(decaMoveChannel, new object[] { pkt });
        }
Example #9
0
 void Update()
 {
     if (joycons.Count > 0)
     {
         // Rotation grâce au gyroscope.
         gameObject.transform.rotation = j.GetVector();
     }
 }
Example #10
0
    // Update is called once per frame
    void Update()
    {
        // make sure the Joycon only gets checked if attached
        if (joycon != null)
        {
            // GetButtonDown checks if a button has been pressed (not held)
            if (joycon.GetButtonDown(Joycon.Button.SHOULDER_1))
            {
                // Joycon has no magnetometer, so it cannot accurately determine its yaw value. Joycon.Recenter allows the user to reset the yaw value.
                joycon.Recenter();
            }

            stick = joycon.GetStick();

            // Gyro values: x, y, z axis values (in radians per second)
            gyro          = joycon.GetGyro();
            gyroMagnitude = gyro.magnitude;

            // Accel values:  x, y, z axis values (in Gs)
            accel          = joycon.GetAccel();
            accelMagnitude = accel.magnitude;

            // fix rotation
            orientation = joycon.GetVector();
            // orientation = new Quaternion(orientation.x, orientation.z, orientation.y, orientation.w);
            //  Quaternion quat = Quaternion.Inverse(orientation);
            //  Vector3 rot = quat.eulerAngles;
            //  rot += rotationOffset;
            // orientation = Quaternion.Euler(rot);
            //  rotation = orientation.eulerAngles;
            if (joyconType == JoyconManager.JoyconType.left)
            {
                gameObject.transform.rotation = Quaternion.Euler(0, Mathf.Abs(orientation.x) * 180 - 90, 0);
            }

            if (joyconType == JoyconManager.JoyconType.right && accelMagnitude > forceNeeded && !cooldown)
            {
                //#if UNITY_STANDALONE_WIN
                voiceR.Reload();
//#endif
                cooldown = true;
                StartCoroutine(BeenSwung());
            }

            // rumble info
            // https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md
            // The last argument (time) in SetRumble is optional. Call it with three arguments to turn it on without telling it when to turn off.
            // (Useful for dynamically changing rumble values.)
            // Then call SetRumble(0,0,0) when you want to turn it off.

            IEnumerator BeenSwung()
            {
                yield return(new WaitForSeconds(cooldownLenght));

                cooldown = false;
            }
        }
    }
Example #11
0
    // Update is called once per frame
    void Update()
    {
        // make sure the Joycon only gets checked if attached
        if (joycons.Count > 0)
        {
            j = joycons[jc_ind];
            // GetButtonDown checks if a button has been pressed (not held)
            if (j.GetButtonDown(Joycon.Button.SHOULDER_2))
            {
                Debug.Log("Shoulder button 2 pressed");
                // GetStick returns a 2-element vector with x/y joystick components
                Debug.Log(string.Format("Stick x: {0:N} Stick y: {1:N}", j.GetStick()[0], j.GetStick()[1]));

                // Joycon has no magnetometer, so it cannot accurately determine its yaw value. Joycon.Recenter allows the user to reset the yaw value.
                j.Recenter();
            }
            // GetButtonDown checks if a button has been released
            if (j.GetButtonUp(Joycon.Button.SHOULDER_2))
            {
                Debug.Log("Shoulder button 2 released");
            }
            // GetButtonDown checks if a button is currently down (pressed or held)
            if (j.GetButton(Joycon.Button.SHOULDER_2))
            {
                Debug.Log("Shoulder button 2 held");
            }

            if (j.GetButtonDown(Joycon.Button.DPAD_DOWN))
            {
                Debug.Log("Rumble");

                // Rumble for 200 milliseconds, with low frequency rumble at 160 Hz and high frequency rumble at 320 Hz. For more information check:
                // https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md

                j.SetRumble(30, 130, 2f, 100);

                // The last argument (time) in SetRumble is optional. Call it with three arguments to turn it on without telling it when to turn off.
                // (Useful for dynamically changing rumble values.)
                // Then call SetRumble(0,0,0) when you want to turn it off.
            }

            stick = j.GetStick();

            // Gyro values: x, y, z axis values (in radians per second)
            gyro = j.GetGyro();

            // Accel values:  x, y, z axis values (in Gs)
            accel = j.GetAccel();

            orientation    = j.GetVector();
            orientation    = Quaternion.Inverse(new Quaternion(orientation.x, orientation.z, orientation.y, orientation.w));
            orientationXYZ = orientation.eulerAngles;
            orientationXYZ = new Vector3(orientationXYZ.x, orientationXYZ.y, orientationXYZ.z);
            gameObject.transform.localRotation = Quaternion.Euler(orientationXYZ);
        }
    }
    public static void SetSensorJoycon(Joycon joycon)
    {
        GetJoyconVector = () =>
        {
            return(joycon.GetVector().eulerAngles);
        };

        GetJoyconGyro = joycon.GetGyro;

        GetJoyconAccel = joycon.GetAccel;
    }
Example #13
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Joycon j = joycons[jc_ind];

        stick = new Vector2(j.GetStick()[0], j.GetStick()[1]);
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/joystick/x", stick.x);
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/joystick/y", stick.y);

        // Gyro values: x, y, z axis values (in radians per second)
        gyro = j.GetGyro();
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/gyro/x", gyro.x);
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/gyro/y", gyro.y);
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/gyro/z", gyro.z);
        // Accel values:  x, y, z axis values (in Gs)
        accel = j.GetAccel();
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/accel/x", accel.x);
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/accel/y", accel.y);
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/accel/z", accel.z);

        orientation = j.GetVector();
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/orientation/0", orientation[0]);
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/orientation/1", orientation[1]);
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/orientation/2", orientation[2]);
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/orientation/3", orientation[3]);

        //Buttons
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/buttons/down", (j.GetButton(Joycon.Button.DPAD_DOWN) ? 1 : 0));
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/buttons/up", (j.GetButton(Joycon.Button.DPAD_UP) ? 1 : 0));
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/buttons/right", (j.GetButton(Joycon.Button.DPAD_RIGHT) ? 1 : 0));
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/buttons/left", (j.GetButton(Joycon.Button.DPAD_LEFT) ? 1 : 0));
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/buttons/minus", (j.GetButton(Joycon.Button.MINUS) ? 1 : 0));
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/buttons/bumper", (j.GetButton(Joycon.Button.SHOULDER_1) ? 1 : 0));
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/buttons/trigger", (j.GetButton(Joycon.Button.SHOULDER_2) ? 1 : 0));
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/buttons/home", (j.GetButton(Joycon.Button.CAPTURE) ? 1 : 0));
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/buttons/joystick", (j.GetButton(Joycon.Button.STICK) ? 1 : 0));
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/buttons/side-top", (j.GetButton(Joycon.Button.SL) ? 1 : 0));
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/buttons/side-bottom", (j.GetButton(Joycon.Button.SR) ? 1 : 0));

        if (rumble == 1)
        {
            j.SetRumble(rumbleFreqLow, rumbleFreqHigh, 0.6f, rumbleLen);
            rumble = 0;
        }


        for (var i = 0; i < OSCHandler.Instance.packets.Count; i++)
        {
            // Process OSC
            receivedOSC(OSCHandler.Instance.packets[i]);
            // Remove them once they have been read.
            OSCHandler.Instance.packets.Remove(OSCHandler.Instance.packets[i]);
            i--;
        }
    }
Example #14
0
    private void GetAngles()
    {
        var orientation = joycon.GetVector().eulerAngles;
        var angles      = transform.localEulerAngles;

        angles.x = orientation.x;
        angles.y = orientation.z;
        angles.z = -orientation.y;

        transform.localEulerAngles = angles;
    }
Example #15
0
    // Start is called before the first frame update
    void Start()
    {
        // set gameobjects
        leftHand  = GameObject.Find("Left12");
        rightHand = GameObject.Find("Right12");

        // set joycons
        List <Joycon> joycons = JoyconManager.Instance.j;

        foreach (var joycon in joycons)
        {
            if (joycon.isLeft)
            {
                leftJoycon = joycon;
            }
            else
            {
                rightJoycon = joycon;
            }
        }

        if (leftJoycon == null)
        {
            Debug.Log("Joycon(L)が見つかりませんでした。");
        }
        else
        {
            leftGusokuBase = leftHand.transform.rotation;
            leftJoyconBase = ConvertRot(leftJoycon.GetVector());
        }
        if (rightJoycon == null)
        {
            Debug.Log("Joycon(R)が見つかりませんでした。");
        }
        else
        {
            rightGusokuBase = rightHand.transform.rotation;
            rightJoyconBase = rightJoycon.GetVector();
        }
    }
Example #16
0
        public string JoyconToString(Joycon j)
        {
            var     hands      = j.isLeft ? "Left" : "Right";
            var     quaternion = j.GetVector();
            float   x          = (float)(quaternion.eulerAngles.X * 180.0f / Math.PI);
            float   y          = (float)(quaternion.eulerAngles.Y * 180.0f / Math.PI);
            float   z          = (float)(quaternion.eulerAngles.Z * 180.0f / Math.PI);
            Vector3 rotate     = new Vector3(x, y, z);
            Vector3 gyro       = j.GetGyro();
            string  result     = "{\"hands\":\"" + hands + "\",\"gyro\":{\"X\":" + gyro.X + ",\"Y\":" + gyro.Y + ",\"Z\":" + gyro.Z + "},\"rotate\":{\"X\":" + rotate.X + ",\"Y\":" + rotate.Y + ",\"Z\":" + rotate.Z + "}}";

            return(result);
        }
 private void FixedUpdate()
 {
     if (joycons.Count > 0)
     {
         Joycon j = joycons[jc_ind];
         if (j.GetButtonDown(Joycon.Button.SHOULDER_2))
         {
             playerController.Attack();
         }
         orientation        = j.GetVector();
         orientation.x     += offset;
         transform.rotation = orientation;
     }
 }
Example #18
0
    // Update is called once per frame
    void Update()
    {
        // make sure the Joycon only gets checked if attached
        if (j != null && j.state > Joycon.state_.ATTACHED)

        {
            stick = j.GetStick();  // Gyro values: x, y, z axis values (in radians per second)
            gyro  = j.GetGyro();

            // Accel values:  x, y, z axis values (in Gs)
            accel = j.GetAccel();

            orientation = j.GetVector();
            smooth      = Mathf.SmoothDamp(smooth, Mathf.Abs(accel.x) * 2, ref v, smoothtime);
            smoother    = Mathf.SmoothDamp(smoother, Mathf.Abs(accel.x) * 2, ref vr, smoothertime);
        }


        gameObject.transform.rotation = orientation;
        if (smooth > 1 && playor == false)
        {
            tuning.Stop();
            song.Play();
            playor = true;
        }
        if (playor == true)
        {
            if (Mathf.Abs(accel.x) < 0.3f)
            {
                timer += Time.deltaTime;
            }
            else
            {
                timer = 0;
            }

            song.pitch = smoother * 1.5f;
            song.pitch = Mathf.Clamp(song.pitch, 0.8f, 1.5f);
            if (timer > 1)
            {
                song.Stop();
            }
            if (timer > 10)
            {
                tuning.Play();
                playor = false;
            }
        }
    }
 public static Quaternion GetJoyConOrientation(bool isLeftJoyCon)
 {
     if (isLeftJoyCon && m_joyconL != null)
     {
         return(m_joyconL.GetVector());
     }
     else if (!isLeftJoyCon && m_joyconR != null)
     {
         return(m_joyconR.GetVector());
     }
     else
     {
         return(Quaternion.identity);
     }
 }
Example #20
0
    private void Update()
    {
        var orientation = m_joyconR.GetVector().eulerAngles;
        var angles      = transform.localEulerAngles;

        angles.z = orientation.y;
        transform.localEulerAngles = angles;

        if (m_joyconR.GetButtonDown(Joycon.Button.SHOULDER_2))
        {
            m_joyconR.Recenter();
        }

        transform.position = new Vector3(0, m_joyconR.GetAccel().magnitude - 1, 0);
    }
    // Update is called once per frame
    void Update()
    {
        stick = j.GetStick();

        // Gyro values: x, y, z axis values (in radians per second)
        gyro = j.GetGyro();

        // Accel values:  x, y, z axis values (in Gs)
        accel = j.GetAccel();

        orientation = j.GetVector();

        OscMessage message = new OscMessage();

        message.address = "/UpdateXYZ";
        message.values.Add(transform.position.x);
        message.values.Add(transform.position.y);
        message.values.Add(transform.position.z);
        osc.Send(message);

        message         = new OscMessage();
        message.address = "/UpdateGyro";
        message.values.Add(gyro[0]);
        message.values.Add(gyro[1]);
        message.values.Add(gyro[2]);
        osc.Send(message);

        message         = new OscMessage();
        message.address = "/UpdateAccel";
        message.values.Add(accel[0]);
        message.values.Add(accel[1]);
        message.values.Add(accel[2]);
        osc.Send(message);

        message         = new OscMessage();
        message.address = "/UpdateOri";
        message.values.Add(orientation[0]);
        message.values.Add(orientation[1]);
        message.values.Add(orientation[2]);
        message.values.Add(orientation[3]);
        osc.Send(message);

        message         = new OscMessage();
        message.address = "/UpdateStick";
        message.values.Add(stick[0]);
        message.values.Add(stick[1]);
        osc.Send(message);
    }
Example #22
0
    void Update()
    {
        if (joycons.Count > 0)
        {
            // Rotation grâce au gyroscope.
            gameObject.transform.rotation = j.GetVector();
        }
        else
        {
            // Rotation grâce aux axes de controles classiques.
            float x = Input.GetAxis("Horizontal");
            float y = Input.GetAxis("Vertical");

            gameObject.transform.Rotate(new Vector3(y * 2, -x * 2));
        }
    }
Example #23
0
    // Update is called once per frame
    void Update()
    {
        // make sure the Joycon only gets checked if attached
        if (j != null && j.state > Joycon.state_.ATTACHED)

        {
            stick = j.GetStick();  // Gyro values: x, y, z axis values (in radians per second)
            gyro  = j.GetGyro();

            // Accel values:  x, y, z axis values (in Gs)
            accel = j.GetAccel();

            orientation = j.GetVector();
        }


        gameObject.transform.rotation = orientation;
        song.pitch         = gyro.y * -0.75f + 1.25f;
        song.reverbZoneMix = accel.x / 2 + 1;
        //song.volume = gyro.x;
    }
Example #24
0
    // Update is called once per frame
    void Update()
    {
        // make sure the Joycon only gets checked if attached
        if (joycon != null)
        {
            // GetButtonDown checks if a button has been pressed (not held)
            if (joycon.GetButtonDown(Joycon.Button.SHOULDER_1))
            {
                // Joycon has no magnetometer, so it cannot accurately determine its yaw value. Joycon.Recenter allows the user to reset the yaw value.
                joycon.Recenter();
            }

            stick = joycon.GetStick();

            // Gyro values: x, y, z axis values (in radians per second)
            gyro          = joycon.GetGyro();
            gyroMagnitude = gyro.magnitude;

            // Accel values:  x, y, z axis values (in Gs)
            accel          = joycon.GetAccel();
            accelMagnitude = accel.magnitude;

            // fix rotation
            orientation = joycon.GetVector();
            orientation = new Quaternion(orientation.x, orientation.z, orientation.y, orientation.w);
            Quaternion quat = Quaternion.Inverse(orientation);
            Vector3    rot  = quat.eulerAngles;
            rot        += rotationOffset;
            orientation = Quaternion.Euler(rot);
            rotation    = orientation.eulerAngles;

            // rumble info
            // https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md
            // The last argument (time) in SetRumble is optional. Call it with three arguments to turn it on without telling it when to turn off.
            // (Useful for dynamically changing rumble values.)
            // Then call SetRumble(0,0,0) when you want to turn it off.
        }
    }
Example #25
0
    void FixedUpdate()
    {
        gameObject.transform.rotation = Quaternion.Euler(90, 0, 0) * j.GetVector(); //switch coordinate systems

        if (j.GetButtonDown(Joycon.Button.SHOULDER_1))                              //reset
        // GetStick returns a 2-element vector with x/y joystick components
        {
            Debug.Log(string.Format("Stick x: {0:N} Stick y: {1:N}", j.GetStick()[0], j.GetStick()[1]));

            // Joycon has no magnetometer, so it cannot accurately determine its yaw value. Joycon.Recenter allows the user to reset the yaw value.
            j.Recenter();
        }

        if (j.GetButtonDown(Joycon.Button.SHOULDER_2))   //capture
        {
            if (currMove != null)
            {
                currMove.StopMove();
                currMove = null;
            }
            else
            {
                RaycastHit hit;
                if (Physics.Raycast(transform.position, transform.forward, out hit))
                {
                    Moveable move = hit.transform.GetComponent <Moveable>();
                    if (move != null)
                    {
                        move.StartMove(j);
                        currMove = move;
                    }
                }
            }
        }

        float[] movement = j.GetStick();
    }
Example #26
0
    // Update is called once per frame
    void Update()
    {
        Debug.Log(base.state);

        // 進行方向をカメラと同期させる
        //   gameObject.transform.rotation = Soulcamera.transform.rotation;

        //  回転を制限
        gameObject.transform.position = new Vector3(gameObject.transform.position.x, Mathf.Clamp(gameObject.transform.position.y, 0, 0), gameObject.transform.position.z);

        // HPを更新
        hpber.value = soulHP;

        // 前進(joyconR-ZR)
        if (m_joyconR.GetButtonDown(Joycon.Button.SHOULDER_2))
        {
            soulVel = 0.08f; text.text = "前進!";
        }
        if (m_joyconR.GetButtonUp(Joycon.Button.SHOULDER_2))
        {
            soulVel = 0.00f; text.text = "停止中";
        }

        // 憑依状態でYを押すと憑依解除
        if (base.state == CONDITION.POSSESSION && m_joyconR.GetButton(Joycon.Button.DPAD_LEFT))
        {
            //number.transform.parent = null;
            // soulConditionFlag = false;
            base.state = CONDITION.NORMAL;
            number.GetComponent <numbers>().SetCondition(CONDITION.NOTPOSSESSION);
        }

        gameObject.transform.localRotation = new Quaternion(0, -m_joyconL.GetVector().z, 0, m_joyconL.GetVector().w);

        gameObject.transform.Translate(0, 0, soulVel);
    }
Example #27
0
    void JoyconMethod()
    {
        // make sure the Joycon only gets checked if attached
        if (joycons.Count > 0)
        {
            Joycon j = joycons [jc_ind];


            // GetButtonDown checks if a button has been pressed (not held)
            if (canSpawnSpriteMask)
            {
                if (j.GetButtonDown(Joycon.Button.SHOULDER_2) && !isCuttingAnim)
                {
                    //Debug.Log ("Shoulder button 2 pressed");
                    j.SetRumble(160, 320, 0.6f, 200);
                    Shrink spriteMask = Instantiate(spriteMaskPrefab, transform.position, transform.rotation);
                    spriteMask.playerRedController = this;
                    numOfMasksSpawnable--;
                    isCuttingAnim = true;
                    audio.Play();
                }
            }


            // GetButtonDown checks if a button has been released
            if (j.GetButtonUp(Joycon.Button.SHOULDER_2))
            {
                //Debug.Log ("Shoulder button 2 released");
                isCuttingAnim = false;
            }
            // GetButtonDown checks if a button is currently down (pressed or held)
            if (j.GetButton(Joycon.Button.SHOULDER_2))
            {
                //Debug.Log ("Shoulder button 2 held");
            }

            if (j.GetButtonDown(Joycon.Button.DPAD_DOWN))
            {
                //Debug.Log ("Rumble");

                // Rumble for 200 milliseconds, with low frequency rumble at 160 Hz and high frequency rumble at 320 Hz. For more information check:
                // https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md

                //j.SetRumble (160, 320, 0.6f, 200);

                // The last argument (time) in SetRumble is optional. Call it with three arguments to turn it on without telling it when to turn off.
                // (Useful for dynamically changing rumble values.)
                // Then call SetRumble(0,0,0) when you want to turn it off.
            }

            stick = j.GetStick();

            // Gyro values: x, y, z axis values (in radians per second)
            gyro = j.GetGyro();

            // Accel values:  x, y, z axis values (in Gs)
            accel = j.GetAccel();

            orientation = j.GetVector();

            if (j.GetButton(Joycon.Button.DPAD_UP))
            {
                transform.Translate(0f, moveSpeedY, 0f, Space.World);
            }
            else
            {
            }

            if (j.GetButton(Joycon.Button.DPAD_DOWN))
            {
                transform.Translate(0f, -moveSpeedY, 0f, Space.World);
            }
            else
            {
            }

            if (j.GetButton(Joycon.Button.DPAD_LEFT))
            {
                transform.Translate(-moveSpeedX, 0f, 0f, Space.World);
            }
            else
            {
            }

            if (j.GetButton(Joycon.Button.DPAD_RIGHT))
            {
                transform.Translate(moveSpeedX, 0f, 0f, Space.World);
            }
            else
            {
            }

            float   zOnly  = orientation.eulerAngles.z;
            Vector3 newRot = new Vector3(gameObject.transform.localRotation.x, gameObject.transform.localRotation.y, zOnly);
            //gameObject.transform.eulerAngles = newRot;


            Quaternion targetRotation = Quaternion.Euler(newRot);
            transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, degreesPerSec * Time.deltaTime);

            //gameObject.transform.rotation = orientation;
        }
    }
Example #28
0
    // Update is called once per frame
    void Update()
    {
        // make sure the Joycon only gets checked if attached
        if (joycons.Count > 0)
        {
            Joycon j = joycons [jc_ind];
            // GetButtonDown checks if a button has been pressed (not held)
            if (j.GetButtonDown(Joycon.Button.SHOULDER_2))
            {
                tilting = true;
                Debug.Log("Shoulder button 2 pressed");
                // GetStick returns a 2-element vector with x/y joystick components
                Debug.Log(string.Format("Stick x: {0:N} Stick y: {1:N}", j.GetStick()[0], j.GetStick()[1]));

                // Joycon has no magnetometer, so it cannot accurately determine its yaw value. Joycon.Recenter allows the user to reset the yaw value.
                j.Recenter();
            }
            // GetButtonDown checks if a button has been released
            if (j.GetButtonUp(Joycon.Button.SHOULDER_2))
            {
                tilting = false;
                Debug.Log("Shoulder button 2 released");
            }
            // GetButtonDown checks if a button is currently down (pressed or held)
            if (j.GetButton(Joycon.Button.SHOULDER_2))
            {
                Debug.Log("Shoulder button 2 held");
            }

            if (j.GetButtonDown(Joycon.Button.DPAD_DOWN))
            {
                Debug.Log("Rumble");

                // Rumble for 200 milliseconds, with low frequency rumble at 160 Hz and high frequency rumble at 320 Hz. For more information check:
                // https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md

                j.SetRumble(160, 320, 0.6f, 200);
                transform.position = Vector3.Lerp(transform.position, new Vector3(0, 0, transform.position.z), 1f);

                // The last argument (time) in SetRumble is optional. Call it with three arguments to turn it on without telling it when to turn off.
                // (Useful for dynamically changing rumble values.)
                // Then call SetRumble(0,0,0) when you want to turn it off.
            }

            stick = j.GetStick();

            // Gyro values: x, y, z axis values (in radians per second)
            gyro = j.GetGyro();

            // Accel values:  x, y, z axis values (in Gs)
            accel = j.GetAccel();

            orientation = j.GetVector();

            if (tilting)
            {
                transform.rotation = new Quaternion(0f, 0f, orientation.z, orientation.w);
            }

            else
            {
                transform.rotation = new Quaternion(0, 0, 0, 0);
                transform.Translate(new Vector3(gyro.z, gyro.y, 0) * Time.deltaTime * speed, Space.World);
            }
        }
    }
Example #29
0
    // Update is called once per frame
    void Update()
    {
        // make sure the Joycon only gets checked if attached
        if (j != null && j.state > Joycon.state_.ATTACHED)

        {
            stick = j.GetStick();  // Gyro values: x, y, z axis values (in radians per second)
            gyro  = j.GetGyro();

            // Accel values:  x, y, z axis values (in Gs)
            accel = j.GetAccel();

            orientation = j.GetVector();
            smooth      = Mathf.SmoothDamp(smooth, Mathf.Abs(average) * 2, ref v, smoothtime);
            smoother    = Mathf.SmoothDamp(smoother, Mathf.Abs(average) * 2, ref vr, smoothertime);
            smoother    = Mathf.Clamp(smoother, 0.8f, 1.2f);
        }

        average = (gyro.x + gyro.y + gyro.z) / 3;

        gameObject.transform.rotation = orientation;
        if (smooth > 1 && playor == false)
        {
            tuning.Stop();
            shoosh.Play();
            song.Play();
            playor            = true;
            crashy            = false;
            songFinishedTimer = 0;
        }
        if (playor == true)
        {
            songFinishedTimer += Time.deltaTime;
            if (Mathf.Abs(average) < 0.3f)
            {
                //timer += Time.deltaTime;
            }
            else
            {
                timer = 0;
            }

            if (timer < 1)
            {
                crashy     = false;
                song.pitch = smoother * 1.5f;
                song.pitch = Mathf.Clamp(song.pitch, 0.8f, 1.5f);
            }
            if (timer > 1)
            {
                song.pitch = 0;
                if (crashy == false)
                {
                    if (songFinishedTimer < 80 && songFinishedTimer > 5)
                    {
                        crash.Play();
                        crashy = true;
                    }
                    else
                    {
                        tuning.Play();
                        playor = false;
                        crashy = true;
                    }
                }
                if (timer > 30.9f)
                {
                    tuning.Play();
                    playor = false;
                }
            }
        }

        if (Mathf.Abs(average) < 0.3f)
        {
            timer += Time.deltaTime;
        }
    }
Example #30
0
    // Update is called once per frame
    void Update()
    {
        // make sure the Joycon only gets checked if attached
        if (joycons.Count > 0)
        {
            Joycon j = joycons[jc_ind];
            // GetButtonDown checks if a button has been pressed (not held)
            if (j.GetButtonDown(Joycon.Button.SHOULDER_2))
            {
                Debug.Log("Shoulder button 2 pressed");
                // GetStick returns a 2-element vector with x/y joystick components
                Debug.Log(string.Format("Stick x: {0:N} Stick y: {1:N}", j.GetStick()[0], j.GetStick()[1]));

                // Joycon has no magnetometer, so it cannot accurately determine its yaw value. Joycon.Recenter allows the user to reset the yaw value.
                j.Recenter();
            }
            // GetButtonDown checks if a button has been released
            if (j.GetButtonUp(Joycon.Button.SHOULDER_2))
            {
                Debug.Log("Shoulder button 2 released");
            }
            // GetButtonDown checks if a button is currently down (pressed or held)
            //Sets win condition
            if (joycons[0].GetButton(Joycon.Button.SHOULDER_2))
            {
                Debug.Log("Shoulder button 2 held");
                for (int x = 0; x < joycons.Count; x++)
                {
                    if (j.GetButton(Joycon.Button.SHOULDER_2))
                    {
                        winner = jc_ind;
                        Debug.Log(winner);
                    }
                }
            }

            if (j.GetButtonDown(Joycon.Button.DPAD_DOWN))
            {
                Debug.Log("Rumble");

                // Rumble for 200 milliseconds, with low frequency rumble at 160 Hz and high frequency rumble at 320 Hz. For more information check:
                // https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md

                j.SetRumble(160, 320, 0.6f, 200);

                // The last argument (time) in SetRumble is optional. Call it with three arguments to turn it on without telling it when to turn off.
                // (Useful for dynamically changing rumble values.)
                // Then call SetRumble(0,0,0) when you want to turn it off.
            }

            stick = j.GetStick();

            // Gyro values: x, y, z axis values (in radians per second)
            gyro = j.GetGyro();

            // Accel values:  x, y, z axis values (in Gs)
            accel = j.GetAccel();


            //sends out rumble signal if movement is sensed
            //determines whether someone needs to go back or not
            if (gyro.x >= 1 || gyro.y >= 1 || gyro.z >= 1 || accel.x >= 1 || accel.y >= 1 || accel.z >= 1 && isRed == true)
            //Debug.Log(jc_ind + "go back");
            {
                whoGoesBack = jc_ind;
                j.SetRumble(160, 320, 0.6f, 200);
                someoneGoesBack = true;
            }
            else
            {
                someoneGoesBack = false;
            }


            orientation = j.GetVector();
            if (j.GetButton(Joycon.Button.DPAD_UP) && jc_ind == 0)
            {
                gameObject.GetComponent <Renderer>().material.color = Color.green;
                isRed = true;
                Debug.Log("dragon is asleep");
            }
            else
            {
                gameObject.GetComponent <Renderer>().material.color = Color.red;
                isRed = true;
                Debug.Log("dragon is awake");
            }
            //gameObject.transform.rotation = orientation;
        }
    }