Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Linking gamepad id to PlayerInputManager player id

Discussion in 'Scripting' started by JamesDonald, Jun 8, 2020.

  1. JamesDonald

    JamesDonald

    Joined:
    Oct 12, 2018
    Posts:
    4
    Hi there,

    I am currently having trouble understanding the best approach to take for implementing gamepad specific rumble for a local multiplayer game.

    Basically I am using the new InputSystem 1.0 to handle players joining. When a player joins the player is assigned with their index representing the order they joined and determining which player they are 1 to 4.

    I need to implement rumble to trigger when the player executes an action. The problem im facing is that the I cannot use the player index to state which gamepad to trigger rumble. From what ive gathered it seems that Unity assigned a different ID to the actual gamepad devices based on the order they are connected/disconnected therefore I cant say , Player 1 joined first, index 0 , gamepad 0 as the gamepad might have been connected third and be indexed at 2 causing the wrong gamepad to rumble, or the controller may become disconnected causing it to change ID when reconnected etc.

    I was just wondering what the best approach to link a player and device would be or if someone could point me in the right direction as I have had no luck so far.

    Thanks!
     
  2. JamesDonald

    JamesDonald

    Joined:
    Oct 12, 2018
    Posts:
    4
    SOLVED

    Going to keep this up in case anyone stumbles across it and is having the same issue.

    InputDevice playerDevice = player_Input.devices[0]; // the only device used for player is controller at index 0
    playerGamepad =(Gamepad)InputSystem.GetDeviceById(playerDevice.deviceId); // cast the device as a gamepad using the associated id.


    playerGamepad.SetMotorSpeeds(f,f);
     
    Aida_Mercury and PraetorBlue like this.