- Home /
 
I can only move left and right with a bluetooth controller, but when wired, it works just fine.
For my game, you have 2 different players, using 2 different controllers. I've never had a problem until I tried to go wireless. All the buttons work fine, but when I load into the game, it only allows me to go left and right. Here's the script for both player 1 and 2: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class Movement : MonoBehaviour { //Movement public float speed; public Rigidbody rb; public float jumpForce; public Transform groundCheck; public float groundDistance = 0.4f; public LayerMask groundMask; public bool isGrounded; public float smoothTime; float turnSmoothVelo = 0.1f; public float dashSpeed; public float dashWait = 2; public bool canDash = true; public float startDashTime;
 //Shields
 public GameObject shield1;
 public GameObject shield2;
 public Health health1;
 public Health health2;
 public int shieldRunTime = 1;
 public int currentRunTime = 1000;
 public Slider slider;
 //Number of Players
 public bool player1;
 public bool player2;
 
 // Start is called before the first frame update
 void Start()
 {
   
 }
 public void setShield()
 {
   
 }
 // Update is called once per frame
 void Update()
 {
     slider.value = currentRunTime;
     if(player1 == true)
     {
         Player1();
         
     }
     if(player2 == true)
     {
         Player2();
     }
     
 }
 public void Player1()
 {
     isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
     
     
     float x = Input.GetAxis("Horizontal1");
     float z = Input.GetAxis("Vertical1");
     Vector3 direction = new Vector3(x, 0f, z).normalized;
     if(direction.magnitude >= 0.1f)
     {
         float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg;
         float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelo, smoothTime);
         transform.rotation = Quaternion.Euler(0f, angle, 0f);
         transform.Translate(direction * speed * Time.deltaTime, Space.World);
        
     }
      
     //Jumping
     if (Input.GetButtonDown("Jump1") && isGrounded)
     {
         rb.AddForce(new Vector3(0, jumpForce, 0), ForceMode.Impulse);
     }
     //Shields
     if (Input.GetButton("Shield1"))
     {
         shield1.active = true;
         currentRunTime -= shieldRunTime;
         health1.damage = 0;
     }
     else
     {
         shield1.active = false;
         health1.damage = 1;
     }
     if(currentRunTime <= 0)
     {
         shield1.active = false;
         shieldRunTime = 0;
     }
     else
     {
         shieldRunTime = 1;
     }
     //Dash
     if (Input.GetButton("Dash1") && canDash == true)
     {
         rb.velocity = direction * dashSpeed;
         canDash = false;
         StartCoroutine(DashWaiting());
     }
 }
 public void Player2()
 {
     isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
     float x = Input.GetAxisRaw("Horizontal2");
     float z = Input.GetAxisRaw("Vertical2");
     Vector3 direction = new Vector3(x, 0f, z).normalized;
     if (direction.magnitude >= 0.1f)
     {
         float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg;
         float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelo, smoothTime);
         transform.rotation = Quaternion.Euler(0f, angle, 0f);
         transform.Translate(direction * speed * Time.deltaTime, Space.World);
     }
     //Jumping
     if (Input.GetButtonDown("Jump2") && isGrounded)
     {
         rb.AddForce(new Vector3(0, jumpForce, 0), ForceMode.Impulse);
     }
     //Shields
     if (Input.GetButton("Shield2"))
     {
         shield2.active = true;
         currentRunTime -= shieldRunTime;
         health2.damage = 0;
     }
     else
     {
         shield2.active = false;
         health2.damage = 1;
     }
     if (currentRunTime <= 0)
     {
         shield2.active = false;
         shieldRunTime = 0;
     }
     else
     {
         shieldRunTime = 1;
     }
     //Dash
     if (Input.GetButton("Dash1") && canDash == true)
     {
         rb.velocity = direction * dashSpeed;
         canDash = false;
         StartCoroutine(DashWaiting());
     }
 }
 public void hoverz()
 {
     rb.AddForce(new Vector3(0, 7, 0), ForceMode.Impulse);
 }
 public IEnumerator DashWaiting()
 {
     yield return new WaitForSeconds(dashWait);
     canDash = true;
 }
 
               }
Now, when I used Bluetooth with both controllers at the same time, Player 1 was only moving left and right, no matter where I rotate the joystick. But, Player 2 was working fine. I disconnected both controllers, restarted unity(because if I plugged in the controllers with a wire, it would be registered as both Player 1 and 3, and Player 2 and 4.), and tried again. Now both players have the same problem. I would like some help on this set back because it's very annoying that it doesn't work all of a sudden.
Your answer
 
             Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Making a bubble level (not a game but work tool) 1 Answer
Spaceship Control Problems 0 Answers
Distribute terrain in zones 3 Answers