void FixedUpdate() { if (joycons.Count > 0) { Joycon j = joycons [jc_ind]; if (j.GetButtonUp(Joycon.Button.SHOULDER_2)) { ActiveBag.Throw(j); } if (j.GetButtonDown(Joycon.Button.DPAD_UP)) { ActiveBag.Reset(); } if (j.GetButton(Joycon.Button.DPAD_LEFT)) { ActiveBag.Move(false); } if (j.GetButton(Joycon.Button.DPAD_RIGHT)) { ActiveBag.Move(true); } if (j.GetButtonDown(Joycon.Button.DPAD_DOWN)) { ActiveBag = gameObject.AddComponent <Application.Bag>(); } // if (j.GetButton(Joycon.Button.STICK)) { // var stickX = j.GetStick()[0]; // if (Mathf.Abs(stickX) > 0.2) { // rotateBag(stickX); // } // } } }
private void Update() { m_pressedButtonL = null; m_pressedButtonR = null; if (m_joycons == null || m_joycons.Count <= 0) { return; } SetControllers(); foreach (var button in m_buttons) { if (m_joyconL != null && m_joyconL.GetButton(button)) { m_pressedButtonL = button; } if (m_joyconR != null && m_joyconR.GetButton(button)) { m_pressedButtonR = button; } } if (Input.GetKeyDown(KeyCode.Z)) { m_joyconL.SetRumble(320, 160, 0.6f, 200); } if (Input.GetKeyDown(KeyCode.X)) { m_joyconR.SetRumble(160, 320, 0.6f, 200); } }
//Effectue le déplacement du joueur sur son axe Y (limitée aux dimensions du Punching Ball) lors du mode POINTING selon la touche pressée. private void moveYAxisPlayer() { float moveSpeed = 0.075f, limit, oldY = gameObject.transform.position.y; //Bouton "Flèche Haut" enfoncé, on augmente la valeur Y de la position du joueur jusqu'à une certaine limite. if (jg.GetButton(Joycon.Button.DPAD_UP)) { limit = bInstance.GetComponent <Collider>().bounds.max.y - (gameObject.transform.lossyScale.y / 2); if (oldY < limit) { gameObject.transform.localPosition += new Vector3(0, moveSpeed, 0); } } //Bouton "Flèche Bas" enfoncé, on diminue la valeur Y de la position du joueur jusqu'à une certaine limite. if (jg.GetButton(Joycon.Button.DPAD_DOWN)) { //On fait en sorte que l'objet joueur ne puisse pas aller sous le Punching Ball. limit = bInstance.GetComponent <Collider>().bounds.min.y + (gameObject.transform.lossyScale.y / 2); if (oldY > limit) { gameObject.transform.localPosition -= new Vector3(0, moveSpeed, 0); } } correctPlayerPosition(); }
/** Checks the controller for its acceleration and switches gravity based on the controller. * Also makes sure we don't call a Gravity Switch when it's not necessary (e.g calling a GravitySwitch(DOWN) when we're already pointing down). * PRECONDITION: There must be a Joycon present to call this code. */ #if UNITY_STANDALONE || UNITY_EDITOR private void GravityCheck() { if ((j.GetButton(Joycon.Button.SL) || j.GetButton(Joycon.Button.SR))) // When holding SL or SR, do not gravity switch. { return; } if ((Mathf.Abs(accel.z)) >= 0.9f) { return; } else if (currGrav != GRAVITY.DOWN && accel.y + (Mathf.Abs(accel.z)) >= 1.0f) // Our controller is upright. Gravity points down. { GravitySwitch(GRAVITY.DOWN); } else if (currGrav != GRAVITY.UP && accel.y + (-Mathf.Abs(accel.z)) <= -1.0f) // Our controller is upside-down. Gravity points up. { GravitySwitch(GRAVITY.UP); } else if (currGrav != GRAVITY.RIGHT && accel.x + (Mathf.Abs(accel.z)) >= 1.0f) // Our controller is 90 degrees clockwise. Gravity points right. { GravitySwitch(GRAVITY.RIGHT); } else if (currGrav != GRAVITY.LEFT && accel.x + (-Mathf.Abs(accel.z)) <= -1.0f) // Our controller is 90 degrees counterclockwise. Gravity points left. { GravitySwitch(GRAVITY.LEFT); } }
void Update() { if (j != null) { j.SetRumble(160, 320, 0.3f, 200); if (j.GetButton(Joycon.Button.DPAD_UP)) { transform.position += (Vector3.forward * SPEED * Time.deltaTime); } if (j.GetButton(Joycon.Button.DPAD_DOWN)) { transform.position += (Vector3.back * SPEED * Time.deltaTime); } if (j.GetButton(Joycon.Button.DPAD_LEFT)) { transform.position += (Vector3.left * SPEED * Time.deltaTime); } if (j.GetButton(Joycon.Button.DPAD_RIGHT)) { transform.position += (Vector3.right * SPEED * Time.deltaTime); } } }
void DeplacementJoycon() { if (mode == (int)Modes.DEPLACEMENT) { stick = j.GetStick(); controls[0] = -stick[1] * vitesse; controls[2] = stick[0] * vitesse; /* Ces boutons pour monter ou descendre */ if (j.GetButton(Joycon.Button.DPAD_RIGHT) && transform.position.y < limit) { controls[1] = vitesse; } else if (j.GetButton(Joycon.Button.DPAD_LEFT) && transform.position.y > -limit) { controls[1] = -vitesse; } else { controls[1] = 0; } transform.position += new Vector3(controls[0], controls[1], controls[2]); } }
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); }
private void handleInput() { // If both buttons are pressed if (rightJoycon.GetButton(Joycon.Button.SR) && leftJoycon.GetButton(Joycon.Button.SL)) { // Begin recording if (!recording) { BeginRecording(); } } // If the buttons are let go else { // Stop recording if (recording) { EndRecording(); Gesture recognized = Recognize(recordingBuffer); if (recognized != null) { lastGestureRecognized = recognized; gestureRecognized = recognized; } } } }
private void handleInput() { // If both buttons are pressed if (rightJoycon.GetButton(Joycon.Button.SR) && leftJoycon.GetButton(Joycon.Button.SL)) { // Begin recording if (!recording) { BeginRecording(); Debug.Log("Start Recording"); } } // If the buttons are let go else { // Stop recording if (recording) { EndRecording(); Debug.Log("End Recording" + " | Count: " + recordingBuffer.Count); } } if (rightJoycon.GetButtonDown(Joycon.Button.HOME) && recordingBuffer.Count > 0) { gesture.data.Add(new List <Gesture.DataPoint>(recordingBuffer)); gesture.SaveData(); Debug.Log(gesture.GetStatus()); recordingBuffer.Clear(); } }
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); //} }
// Update is called once per frame void Update() { m_pressedButtonL = null; m_pressedButtonR = null; timer += 0.1f * Time.deltaTime; if (m_joyconL != null) { foreach (var button in m_buttons) { if (m_joyconL.GetButton(button)) { m_pressedButtonL = button; } if (m_joyconR.GetButton(button)) { m_pressedButtonR = button; } } SetJoyCon(); JoyConAction(); } //Debug.Log(joyconDec.button); }
void DeplacementJoycon() { stick = j.GetStick(); if (j.isLeft) { controls[0] = -stick[1] * vitesse; controls[2] = stick[0] * vitesse; /* Ces boutons pour monter ou descendre */ if (j.GetButton(Joycon.Button.DPAD_RIGHT) && transform.localPosition.y < limit) { controls[1] = vitesse; } else if (j.GetButton(Joycon.Button.DPAD_LEFT) && transform.localPosition.y > -limit) { controls[1] = -vitesse; } else { controls[1] = 0; } } else { controls[0] = stick[1] * vitesse; controls[2] = -stick[0] * vitesse; /* Ces boutons pour monter ou descendre */ if (j.GetButton(Joycon.Button.DPAD_LEFT) && transform.localPosition.y < limit) { controls[1] = vitesse; } else if (j.GetButton(Joycon.Button.DPAD_RIGHT) && transform.localPosition.y > -limit) { controls[1] = -vitesse; } else { controls[1] = 0; } } /* Le sommet bouge dans le domaine local, donc par rapport à son objet parent et non par rapport au monde. */ transform.localPosition += new Vector3(controls[0], controls[1], controls[2]); }
// Update is called once per frame void Update() { if (isDead) { if (joy != null) { if (joy.GetButton(Joycon.Button.SR) || joy.GetButton(Joycon.Button.SL)) { Reset(); } } if (Input.GetKeyDown(KeyCode.R)) { Reset(); } } }
// 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); } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Space)) { controls.input.command = Command.Jump; } else if ((Input.GetKeyDown(KeyCode.Q) && Input.GetKey(KeyCode.LeftShift)) || GestureRecognitionSystem.GetGestureRecognized(GestureType.LeftBend)) { controls.input.command = Command.LeftBend; } else if ((Input.GetKeyDown(KeyCode.W) && Input.GetKey(KeyCode.LeftShift)) || GestureRecognitionSystem.GetGestureRecognized(GestureType.UpBend)) { controls.input.command = Command.UpBend; } else if ((Input.GetKeyDown(KeyCode.E) && Input.GetKey(KeyCode.LeftShift)) || GestureRecognitionSystem.GetGestureRecognized(GestureType.RightBend)) { controls.input.command = Command.RightBend; } else if (Input.GetKeyDown(KeyCode.Q) || GestureRecognitionSystem.GetGestureRecognized(GestureType.LeftPunch)) { controls.input.command = Command.LeftPunch; } else if (Input.GetKeyDown(KeyCode.W) || GestureRecognitionSystem.GetGestureRecognized(GestureType.UpperCut)) { controls.input.command = Command.UpPunch; } else if (Input.GetKeyDown(KeyCode.E) || GestureRecognitionSystem.GetGestureRecognized(GestureType.RightPunch)) { controls.input.command = Command.RightPunch; } else if (Input.GetKey(KeyCode.A) || (leftJoycon != null && leftJoycon.GetButton(Joycon.Button.SHOULDER_1))) { controls.input.command = Command.Left; } else if (Input.GetKey(KeyCode.D) || (rightJoycon != null && rightJoycon.GetButton(Joycon.Button.SHOULDER_1))) { controls.input.command = Command.Right; } else if (Input.GetKey(KeyCode.R) || rightJoycon != null && rightJoycon.GetButton(Joycon.Button.HOME)) { controls.input.command = Command.Reset; } }
public bool GetKeyStay(Joycon.Button button, bool isLeft) { if (isLeft) { return(m_joyconL.GetButton(button)); } else { return(m_joyconR.GetButton(button)); } }
// 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--; } }
// Update is called once per frame void Update() { Checkpoint(); if (isDead) { #if UNITY_STANDALONE || UNITY_EDITOR if (joy != null) { if (joy.GetButton(Joycon.Button.SR) || joy.GetButton(Joycon.Button.SL)) { Reset(); } } #endif if (Input.GetKeyDown(KeyCode.R)) { Reset(); } } }
///<summary> ///Checks if a shoulder button was pressed and on which controller ///</summary> private void PushedButton() { if (joyconLeft != null && joyconRight != null) { if (!wasPushed && joyconRight.GetButton(Joycon.Button.SHOULDER_2)) { PickUp(); wasPushed = true; joyconLeft.SetRumble(160.0f, 320.0f, 0.6f, 1000); joyconRight.SetRumble(160.0f, 320.0f, 0.6f, 1000); } if (wasPushed && isHolding && joyconRight.GetButton(Joycon.Button.SHOULDER_1)) { item.GetComponent <Rigidbody>().AddForce(tempParent.transform.forward * throwForce); joyconLeft.SetRumble(lowerLimit, upperLimit, amplitude, 1000); joyconRight.SetRumble(lowerLimit, upperLimit, amplitude, 1000); isHolding = false; wasPushed = false; } } else if (joyconLeft != null) { if (!wasPushed && joyconLeft.GetButton(Joycon.Button.SHOULDER_2)) { PickUp(); wasPushed = true; joyconLeft.SetRumble(160.0f, 320.0f, 0.6f, 1000); } if (wasPushed && isHolding && joyconLeft.GetButton(Joycon.Button.SHOULDER_1)) { item.GetComponent <Rigidbody>().AddForce(tempParent.transform.forward * throwForce); joyconLeft.SetRumble(lowerLimit, upperLimit, amplitude, 1000); isHolding = false; wasPushed = false; } } }
private void Update() { //m_joyconL.SetRumble( 160, 320, 0.6f, 200 ); // 振動 m_pressedButtonL = null; m_pressedButtonR = null; if (m_joyconL.GetButtonDown(Joycon.Button.DPAD_RIGHT)) { // number = Random.Range(0, Train.Length); Instantiate(Train[0], transform.position, transform.rotation); // 右ボタンが押された // number = Random.Range(0, Train.Length); //Instantiate(Train[number], transform.position, transform.rotation); } 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); } }
private void Update() { if (!m_Jump) { if (joycons.Count > 0) { if (j.isLeft) { m_Jump = j.GetButton(Joycon.Button.DPAD_RIGHT); } else { m_Jump = j.GetButton(Joycon.Button.DPAD_LEFT); } } else { m_Jump = Input.GetButtonDown("Jump"); } } }
private void Update() { m_pressedButtonL = null; m_pressedButtonR = null; if (m_joycons == null || m_joycons.Count <= 0) { return; } SetControllers(); 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); } for (int i = 0; i < isShake.Length; i++) { if (isShake[i]) { SendDisturb(i); } } }
/** Checks the controller for its acceleration and switches gravity based on the controller. * Also makes sure we don't call a Gravity Switch when it's not necessary (e.g calling a GravitySwitch(DOWN) when we're already pointing down). * PRECONDITION: There must be a Joycon present to call this code. */ private void GravityCheck() { if (!j.GetButton(Joycon.Button.SHOULDER_2)) { return; } if (currGrav != GRAVITY.DOWN && accel.y + (Mathf.Abs(accel.z)) >= 1.0f) // Our controller is upright. Gravity points down. { GravitySwitch(GRAVITY.DOWN); } else if (currGrav != GRAVITY.UP && accel.y + (-Mathf.Abs(accel.z)) <= -1.0f) // Our controller is upside-down. Gravity points up. { GravitySwitch(GRAVITY.UP); } else if (currGrav != GRAVITY.RIGHT && accel.x + (Mathf.Abs(accel.z)) >= 1.0f) // Our controller is 90 degrees clockwise. Gravity points right. { GravitySwitch(GRAVITY.RIGHT); } else if (currGrav != GRAVITY.LEFT && accel.x + (-Mathf.Abs(accel.z)) <= -1.0f) // Our controller is 90 degrees counterclockwise. Gravity points left. { GravitySwitch(GRAVITY.LEFT); } }
// 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); }
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; } }
// Update is called once per frame void Update() { if (joycons.Count > 0) { stick = j.GetStick(); if (j.isLeft) { if (transform.position.x < limitX && stick[1] < 0) { controls[0] = -stick[1] * vitesse; } else if (transform.position.x > -limitX && stick[1] > 0) { controls[0] = -stick[1] * vitesse; } else { controls[0] = 0; } if (transform.position.y < limitY && stick[0] > 0) { controls[1] = stick[0] * vitesse; } else if (transform.position.y > 0 && stick[0] < 0) { controls[1] = stick[0] * vitesse; } else { controls[1] = 0; } if (j.GetButton(Joycon.Button.DPAD_DOWN) && delay >= beamRate) { Instantiate(projectile, firePoint.position, firePoint.rotation); delay = 0; } } else { if (transform.position.x < limitX && stick[1] > 0) { controls[0] = stick[1] * vitesse; } else if (transform.position.x > -limitX && stick[1] < 0) { controls[0] = stick[1] * vitesse; } else { controls[0] = 0; } if (transform.position.y < limitY && stick[0] < 0) { controls[1] = -stick[0] * vitesse; } else if (transform.position.y > 0 && stick[0] > 0) { controls[1] = -stick[0] * vitesse; } else { controls[1] = 0; } if (j.GetButton(Joycon.Button.DPAD_UP) && delay >= beamRate) { Instantiate(projectile, firePoint.position, firePoint.rotation); delay = 0; } } transform.position += new Vector3(controls[0], controls[1], 0); } else { float x = Input.GetAxis("Horizontal"); float y = Input.GetAxis("Vertical"); if (transform.position.x < limitX && x > 0) { controls[0] = x * vitesse; } else if (transform.position.x > -limitX && x < 0) { controls[0] = x * vitesse; } else { controls[0] = 0; } if (transform.position.y < limitY && y > 0) { controls[1] = y * vitesse; } else if (transform.position.y > 0 && y < 0) { controls[1] = y * vitesse; } else { controls[1] = 0; } if (Input.GetButton("Fire2") && delay >= beamRate) { Instantiate(projectile, firePoint.position, firePoint.rotation); delay = 0; } transform.position += new Vector3(controls[0], controls[1], 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); } } }
// Update is called once per frame void Update() { // later: prioritise based on input. if ((useKeys && Input.GetKey(KeyCode.L)) || (!useKeys && j.GetButton(j.isLeft ? Joycon.Button.DPAD_DOWN : Joycon.Button.DPAD_UP))) { pc.fireProjectile(); } if ((useKeys && Input.GetKey(KeyCode.I)) || (!useKeys && j.GetButton(j.isLeft ? Joycon.Button.DPAD_RIGHT : Joycon.Button.DPAD_LEFT))) { pc.altProjectile(); } if ((!useKeys && j.GetButtonDown(j.isLeft ? Joycon.Button.DPAD_LEFT : Joycon.Button.DPAD_RIGHT)) || (useKeys && Input.GetKeyDown(KeyCode.K))) { pc.attemptUse(); } pc.flyDirection(useKeys ? getKeyboardMoveVec() : new Vector2((j.isLeft ? -1 : 1) * j.GetStick()[1], (j.isLeft ? -1 : 1) * -j.GetStick()[0])); /** * // 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(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)) * { * gameObject.GetComponent<Renderer>().material.color = Color.red; * } * else * { * gameObject.GetComponent<Renderer>().material.color = Color.blue; * } * gameObject.transform.rotation = orientation; */ }
// 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; } }
// 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(); gameObject.transform.position = Vector3.zero; } // 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(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. } if (j.GetButton(Joycon.Button.DPAD_UP)) { gameObject.GetComponent <Renderer>().material.color = Color.red; } else { gameObject.GetComponent <Renderer>().material.color = Color.yellow; } 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(); accel1 = j.GetAccel1(); accel2 = j.GetAccel2(); accel3 = j.GetAccel3(); bool isMoving = false; bool debug = false; if (gyro.x > angle_mort || gyro.x < -angle_mort || debug) { isMoving = true; orientation.x = j.GetVector().x; } if (gyro.y > angle_mort || gyro.y < -angle_mort || debug) { isMoving = true; orientation.y = j.GetVector().y; } if (gyro.z > angle_mort || gyro.z < -angle_mort || debug) { isMoving = true; orientation.z = j.GetVector().z; } if (isMoving) { orientation.w = j.GetVector().w; gameObject.transform.rotation = orientation; } gameObject.transform.position = new Vector3(accel3.x * vitesse, accel1.y * vitesse, accel3.z * vitesse); cursor1.transform.position = accel1; cursor2.transform.position = accel2; cursor3.transform.position = accel3; cursor4.transform.position = accel1 + accel2 + accel3; } }