playMaker

Author Topic: Unable to get input from separate controllers' analog sticks  (Read 1341 times)

Repomensch

  • Playmaker Newbie
  • *
  • Posts: 4
Unable to get input from separate controllers' analog sticks
« on: January 24, 2016, 06:44:44 PM »
TL;DR - I'm making a multiplayer game. Buttons and triggers only effect one character as expected, but analog sticks effect all characters.

I am making a top-down dual-stick action game with local multiplayer featuring identical characters. I can press the A button on a controller and spawn a character prefab. His controls are as follows:
  • Left Stick - Movement
  • Right Stick - Aiming
  • Right Button - Melee Attack
  • Left Trigger (Hold) - Enter Ranged Mode
  • Right Button (While in Ranged Mode) - Shoot Projectile

This all works for one character and pressing the A button on a second controller spawns the second character. [EDIT]: However, the sticks on the first controller cease to have any apparent effect, and the sticks on the second controller move and aim both characters.

What's strange is that, despite being handled in the exact same way as the analog sticks, the Right Button and Left Trigger functions both operate as expected. That is, the buttons of one controller effect one character only. So, I seem to have it figured out for RB (Get Button Down) and LT (Get Axis), yet the same solution does not work for the analog sticks (using either Get Axis or Get Axis Vector, depending on the situation).

This is how it's set up:
  • All necessary axes and buttons are set up in the Input Manager as four separate inputs. Buttons are called in the form "joystick x button y". Joy Num is set properly to Joysticks 1-4.
  • A spawner FSM in the scene listens for A to be pressed on each of four controllers, sets (global int)addedPlayerNumber to a corresponding digit (1-4) and then creates the prefab at the location of a specific spawn point.
  • A character FSM checks addedPlayerNumber, assigns the corresponding Input Manager axes to local strings, and then uses those strings to get the values of all controllers' axes and store them in global variables on a constant basis.
  • Another FSM on the character uses Add Force and Smooth Look At Direction to move and aim the character, using the global input variables.
  • FSMs on the melee and ranged weapons use Float Compare to listen for the mode change with LT and use Bool Test to register presses of RB, again using the global input variables.

I had thought the issue was using global variables to store input, but since RB and LT both work, it seems safe to assume that each character knows which globals belong to it. My Input Manager looks nearly identical to those I've found online that claim to have accomplished local multiplayer.

Can anyone shed some light on this issue?
« Last Edit: January 24, 2016, 07:16:43 PM by Repomensch »

Repomensch

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Unable to get input from separate controllers' analog sticks
« Reply #1 on: January 24, 2016, 07:39:51 PM »
I found the solution:

In my FSM that handles movement, I set local variables to the value of the global variables, and then used the local versions of the variables to manipulate the character's movement and aiming.