private void mouvementJoycon() { // Pour changer de mode de controle. if (j.GetButtonDown(Joycon.Button.DPAD_DOWN)) { mode = (int)ModeControles.DETECTION; } if (j.GetButtonDown(Joycon.Button.DPAD_UP)) { mode = (int)ModeControles.ANALOGIQUE; } if (mode == (int)ModeControles.DETECTION) { accel = j.GetAccel(); //Arrondissement à la décimale inférieure (pour limiter les tremblements) float x = (float)((int)(accel.x * 100)) / 100; float y = (float)((int)(accel.y * 100)) / 100; gameObject.transform.rotation = Quaternion.Euler(y * vitesse, 180, x * vitesse); } else if (mode == (int)ModeControles.ANALOGIQUE) { stick = j.GetStick(); gameObject.transform.rotation = Quaternion.Euler(-j.GetStick()[0] * vitesse, 180, -j.GetStick()[1] * vitesse); } }
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; }
// 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); } }
void DeplacementJoycon() { if (mode == (int)Modes.DEPLACEMENT) { 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.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; } } 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.position.y < limit) { controls[1] = vitesse; } else if (j.GetButton(Joycon.Button.DPAD_RIGHT) && transform.position.y > -limit) { controls[1] = -vitesse; } else { controls[1] = 0; } } if (personnage != null) { transform.position = personnage.transform.position; } else { transform.position += new Vector3(controls[0], controls[1], controls[2]); } } }
// 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--; } }
protected virtual void LateUpdate() { //1f前のボタンを入れる foreach (ButtonCode button in Enum.GetValues(typeof(ButtonCode))) { oldButton[button] = GetButton(button); //Debug.Log(button + GetButton(button).ToString()); } if (stickJoycon != null) { beforeHorizontalValue = stickJoycon.GetStick()[1]; beforeVerticalValue = stickJoycon.GetStick()[0]; } }
//プレイヤーの移動 private void PlayerMove() { for (int i = 0; i < joycons.Count; i++) { Joycon inProcJoycon = joycons[i]; //スティックの入力値をジョイコンの数分格納 Vector2 stickInput = (new Vector2(inProcJoycon.GetStick()[0], inProcJoycon.GetStick()[1]) * parameter.moveSpeed); parameter.moveVel += EasingLerps.OutQuad(parameter.oldVel, stickInput, parameter.accelSpeed * Time.fixedDeltaTime) / joycons.Count; } //格納された値を補間して速度に代入 rigidbody2D.velocity = parameter.moveVel; parameter.ResetVel(); }
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); } var stick = m_joyconL.GetStick(); // スティック }
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; } }
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; }
private void GetInput(out float speed) { Joycon j = JoyconManager.Instance.j[1]; float[] position = j.GetStick(); // Read input float horizontal = position[0]; float vertical = position[1]; bool waswalking = m_IsWalking; #if !MOBILE_INPUT // On standalone builds, walk/run speed is modified by a key press. // keep track of whether or not the character is walking or running m_IsWalking = !Input.GetKey(KeyCode.LeftShift); #endif // set the desired speed to be walking or running speed = m_IsWalking ? m_WalkSpeed : m_RunSpeed; m_Input = new Vector2(horizontal, vertical); // normalize input if it exceeds 1 in combined length: if (m_Input.sqrMagnitude > 1) { m_Input.Normalize(); } // handle speed change to give an fov kick // only if the player is going to a run, is running and the fovkick is to be used if (m_IsWalking != waswalking && m_UseFovKick && m_CharacterController.velocity.sqrMagnitude > 0) { StopAllCoroutines(); StartCoroutine(!m_IsWalking ? m_FovKick.FOVKickUp() : m_FovKick.FOVKickDown()); } }
// 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; } } }
// Update is called once per frame void Update() { if (!bug) { float lsx = jg.GetStick()[0], lsy = jg.GetStick()[1], rsx = jd.GetStick()[0], rsy = jd.GetStick()[1]; stickMovements(lsx, lsy, rsx, rsy, 25f); //Bouton X pressé et il est encore possible de changer de matériau. if (jd.GetButtonDown(Joycon.Button.DPAD_UP) && (changeMat)) { switchMaterial(); } //Bouton A pressé et possibilité de créer un clone. if (jd.GetButtonDown(Joycon.Button.DPAD_RIGHT) && (!copy)) { StartCoroutine("createClone"); } //Bouton Flèche haute pressé et il est encore possible de changer de matériau. if (jg.GetButtonDown(Joycon.Button.DPAD_UP) && (changeMat)) { Transform canvas = gameObject.transform.GetChild(0).GetChild(0); int nbgen = canvas.GetComponent <MG_Life_Canvas>().getNbGen(); canvas.GetComponent <MG_Life_Canvas>().setNbGen(nbgen + 1); } //Bouton Flèche bas pressé et possibilité de changer de matériau. if (jg.GetButtonDown(Joycon.Button.DPAD_DOWN) && (changeMat)) { Transform canvas = gameObject.transform.GetChild(0).GetChild(0); int nbgen = canvas.GetComponent <MG_Life_Canvas>().getNbGen(); canvas.GetComponent <MG_Life_Canvas>().setNbGen(nbgen - 1); } //Bouton B pressé. On supprime tout les clones générés et on peut de nouveau changer de matériau. if (jd.GetButtonDown(Joycon.Button.DPAD_DOWN)) { GameObject[] objects = GameObject.FindGameObjectsWithTag("Copy"); foreach (GameObject go in objects) { Destroy(go); } if (!changeMat) { changeMat = true; } } } }
private void RotateView() { Joycon j = JoyconManager.Instance.j[0]; float[] rotation = j.GetStick(); m_Camera.transform.rotation = m_Camera.transform.rotation * Quaternion.Euler(0, rotation[0] * 3, 0); //m_MouseLook.LookRotation (transform, m_Camera.transform); }
int SelectNudge() { Vector2 stickSelection; //Gets the floats for the stick axis float [] input = current.GetStick(); //Moves axis data into a vec2 stickSelection.y = input[0]; stickSelection.x = input[1]; //Calculates which direction the joystick is going //and returns a number to represent direction if (!current.isLeft) { if (stickSelection.y > 0.5) //Player 3 { return(3); } if (stickSelection.y < -0.5) //Player 1 { return(1); } if (stickSelection.x > 0.5) //Player 2 { return(2); } if (stickSelection.x < -0.5) //Player 4 { return(4); } } else { if (stickSelection.y > 0.5) //Player 1 { return(1); } if (stickSelection.y < -0.5) //Player 4 { return(3); } if (stickSelection.x > 0.5) //Player 2 { return(4); } if (stickSelection.x < -0.5) //Player 4 { return(2); } } return(0); }
// Update is called once per frame void Update() { // var hori = Input.GetAxis("Horizontal"); // var vert = Input.GetAxis("Vertical"); var stick = joyconr.GetStick(); var direction = new Vector3(stick[1], 0f, -stick[0]); transform.position += direction * Time.deltaTime * speed; if (Input.GetKey(KeyCode.Space)) { cCon.Move(moveDirection * Time.deltaTime); } }
private void Mouvements() { float h, v; if (joycons.Count > 0) { if (j.isLeft) { h = -j.GetStick()[1] * vitesseH; v = j.GetStick()[0] * vitesseV; aim = j.GetButtonDown(Joycon.Button.DPAD_DOWN); } else { h = j.GetStick()[1] * vitesseH; v = -j.GetStick()[0] * vitesseV; aim = j.GetButtonDown(Joycon.Button.DPAD_UP); } } else { h = Input.GetAxis("Horizontal") * vitesseH; v = Input.GetAxis("Vertical") * vitesseV; aim = Input.GetButtonDown("Fire2"); } /* Pour bloquer la position entre les limites en hauteur. */ if (transform.position.y <= HauteurMin && v < 0) { v = 0; } else if (transform.position.y >= HauteurMax && v > 0) { v = 0; } transform.rotation = Quaternion.Euler(0, h + transform.rotation.eulerAngles.y, 0); transform.position += new Vector3(0, v); }
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(); }
// 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; } } }
// Update is called once per frame void Update() { if (joycons.Count > 0) { Joycon j = joycons[main.currentJoyconMouth]; if (joycons.Count > 0) { stick = j.GetStick(); if (planeCanRotate == true) { if (/*Droite*/ (main.currentJoyconPlayer == 1 && j.GetStick()[1] < -0.6f) || (main.currentJoyconPlayer == 0 && j.GetStick()[1] > 0.6f)) { transform.Rotate(0, rotationSpeed * Time.deltaTime, 0, Space.Self); } if (/*Gauche*/ (main.currentJoyconPlayer == 1 && j.GetStick()[1] > 0.6f) || (main.currentJoyconPlayer == 0 && j.GetStick()[1] < -0.6f)) { transform.Rotate(0, rotationSpeed * Time.deltaTime * -1, 0, Space.Self); } } } } else { if (planeCanRotate == true) { if (/*Droite*/ (main.currentJoyconMouth == 1 && Input.GetAxis("JoystickX_P2") > 0.6f) || (main.currentJoyconMouth == 0 && Input.GetAxis("JoystickX_P1") > 0.6f)) { transform.Rotate(0, rotationSpeed * Time.deltaTime, 0, Space.Self); } if (/*Gauche*/ (main.currentJoyconMouth == 1 && Input.GetAxis("JoystickX_P2") < -0.6f) || (main.currentJoyconMouth == 0 && Input.GetAxis("JoystickX_P1") < -0.6f)) { transform.Rotate(0, rotationSpeed * Time.deltaTime * -1, 0, Space.Self); } } } }
public static float[] Getstick(bool isLeftJoyCon) { if (isLeftJoyCon && m_joyconL != null) { return(m_joyconL.GetStick()); } else if (!isLeftJoyCon && m_joyconR != null) { return(m_joyconR.GetStick()); } else { return new float[] { 0, 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); }
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() { // 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)) { // Joycon has no magnetometer, so it cannot accurately determine its yaw value. Joycon.Recenter allows the user to reset the yaw value. j.Recenter(); } var stickX = j.GetStick()[0]; if (Mathf.Abs(stickX) > 0.2) { ActiveBag.Rotate(stickX); } } }
// Update is called once per frame void Update() { stick = j.GetStick(); gyro = j.GetGyro(); accel = j.GetAccel(); if (FixableItemController.locked) { if ((Input.GetKeyDown(KeyCode.Return) || accel.magnitude > 3) && locked && dragonImage.fillAmount >= 0.75f) { locked = !locked; dragCon.flameFill.fillAmount -= 0.01f; } else if (dragonImage.fillAmount <= 0f && !locked) { t = 0; powerBar.value = 0; locked = !locked; } else if ((Input.GetKeyDown(KeyCode.Return) || accel.magnitude > 3) && dragonImage.fillAmount > 0f) { dragCon.flameFill.fillAmount -= 0.01f; j.SetRumble(50, 50, 5.0f, 1000); if (powerBar.value >= sweetSpotMin && powerBar.value <= sweetSpotMax) { Debug.Log("BING - GOOD"); GameController.overallGameScore += 1; Debug.Log("Score: " + GameController.overallGameScore); } else { Debug.Log("BONG - BAD"); } } if (!locked) { t += Time.deltaTime; powerBar.value = Mathf.Abs(Mathf.Sin(t)); } } }
// 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; }
// 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. } }
// Update is called once per frame void Update() { float[] stick = JoyconR.GetStick(); Debug.Log(stick.Length); Debug.Log("stick0 " + stick[0]); Debug.Log("stick1 " + stick[1]); if (stick[0] > 0.7) { cube.transform.position += Vector3.right * Time.deltaTime; } if (stick[0] < -0.7) { cube.transform.position += -Vector3.right * Time.deltaTime; } if (stick[1] > 0.7) { cube.transform.position += Vector3.forward * Time.deltaTime; } if (stick[1] < -0.7) { cube.transform.position += -Vector3.forward * Time.deltaTime; } }
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); } }