Unity Local 2 Player combination of controller and keyboard controllers - c#

I am working on a local multiplayer Unity based game. I want to allow Player 1 to use the keyboard to control their character while Player 2 uses an xbox 360 controller. The issue that I am having is that the controller is only registering as Joystick 1. Here is what I have done so far:
I set up two separate inputs, one polling joystick1 and the keyboard for player 1 with another polling joystick2 (and some alternate keyboard keys) for player 2.
I have the system working with both players on the keyboard, but am unable to get player 1 to use the keyboard while player 2 uses the controller (or visa versa).
My question is, how can I force a controller to become joystick2 or joystick1? Is there a way to control which input is registered to which number?

I'm looking for that solution as well. It seems like Portal2 has managed to get a keyboard+mouse / xbox360controller for local cooperative play, but people have been struggling to get it to work because of this same problem, seems like switching player number in the 360controller is tricky.
Portal2 post on this matter
https://steamcommunity.com/sharedfiles/filedetails/?id=239373369

Related

Deactivate or disable Controller/Gamepad functions for another process in C#

I am writing a little Windows Forms application in C# to detect if a XBox Controller is connected and if it does, it maps the gamepad buttons to specific keyboard keys (with SharpDX and InputSimulator). After that it starts a game where I want to use my own configuration. This all works great.
Unfortunately the game has built in controller support and always prioritizes its own button mapping and the problem is, that it only supports 3 buttons on the gamepad.
Now is the question if it is possible in C# to forbid, deactivate or disable the use of the gamepad for another process so it (that specific process) thinks there is no gamepad it can use?
I don't know if this helps, but the games I want to use my tool with, are made in RPG Maker 2003 to make those games fully controller compatible. Maybe there is a way to just deactivate it in the game itself and I don't know how?

How to validate chess moves with a server? Winboard and Unity 2020.3

I'm looking for advice on how to implement online chess move validation using a winboard chess engine. I am creating a mobile battle chess game in Unity 2020.3. Right now I have the possible moves for each player, castle rights, check status, etc being generated by an open source C# chess engine. I chose this engine because it's written in C# and the code could be directly included in my Unity Project. I successfully wrote my own code that connects this chess engine to a 3D battle chess game.
How the game works (video preview):
A piece is selected by the player clicking it with their mouse or
tapping the screen.
The possible moves for the current board are calculated by the chess engine.
I use the possible move indexes to show possible move highlights.
When a player makes one of these possible moves, the move is applied on the chess engine.
It becomes the other player's turn.
I have some custom code to run player animations, based on the kind of move (ex. an attack animation runs when a piece is captured). I also show have screens that show when it's time for a promotion, a player is in check, or the game is over.
I'd like to somehow make the process of calculating possible moves and applying moves to be done on a server. My goal is to protect from players sending illegal moves to the board and breaking the game.
How would you recommend I approach this problem? This is the last thing I need to turn this game into an enjoyable online experience. I just lack the crucial skill of understanding how to make this game online.
On the server, you'll have a separate version of the chess game running.
A player(/client) will send a move to the server (so a unique piece ID, and the target square the player wants to move).
On the server-side, you'll need to check to see if that move is indeed possible. This could be by getting all possible moves from that piece, and checking to see if the intendedChessPosition can be found in the list of possibleChessPositions that was calculated on server-side. Only then, will you actually move the piece server-side.
All players/clients will communicate using the server as the middleman and authority.
The exact implementation could change depending on the API of the chess engine you're using, but that's the basic idea.

Is it possible set multiple controller inputs at runtime?

Pre Notes
I'm creating a 4-player, multiplayer game.
I have 4 identical controllers that are like USB SNES controllers.
All the controllers work and input great.
I want this game to work on multiple platforms, devices, etc.
Here's the issue:
When I start the game, the controllers are auto-mapped as follows...
Player 1: controller 1
Player 2: controller 2
Player 3: controller 3
Player 4: controller 6
I'm assuming that if I change the order the controllers are plugged in, or run this on a different computer/device, or use different controllers, etc., the input mapping will certainly not be what is auto-mapped to above.
My Question:
I do have a script that detects which controller is inputing. (e.g. the JoyNum, which is how I figured out that Player 4 was controller 6)
Given that, is it possible to set Unity's default "Input Manager's" JoyNums at runtime to compensate?
My thoughts were to create a screen where everyone pushes start to join the game. At that point, I will be able to detect all the controllers. (E.g. which JoyNum each player is) The last step will be re-mapping Unity's Input Manager. Is this possible?
Thanks!
PS: I searched and found "Custom Input Manager" on Git, https://github.com/daemon3000/InputManager
However, the project doesn't build, and I have no idea how to implement it.
So, after much trial and error, I came up with a solution that works. (Probably not the cleanest/recommended approach though)
Step 1) Add every Joystick Axis (all 28), for every controller (all 8) in your Input Manager. (A script can make this very easy/much less time consuming)
Step 2) Create your own Input Mapper. (Detect the "up", and "left" of every controller.)
Step 3) Save those results to the "PlayerPrefs" file.
Step 4) Create your own Input detection script. (The only things that needs to access Unity's Input Manager are the Joystick Axis'.) The other buttons can be done manually from the (strings) loaded from the PlayerPrefs file.
Pros of this approach:
Works as a catch all. (For any controller, device, computer, etc.)
Is very stable!
Allows for maximum control over all inputs and what they do.
Cons:
Seems a little ridiculous to have to do all this.
Fairly time consuming. (But can easily be used again on future projects)
Seems sloppy, but works great.

VRTK & SteamVR Local Multiplayer

How do I go about inserting another independent camera rig which can be used to navigate using mouse & keyboard in the same scene as the VR player, together with the VR player, with an independent camera view? Does VRTK/SteamVR natively have this feature?
In other words, I'd like to know how to implement asymmetrical local multiplayer, similar to the 'Panoptic' demo.
Yes VRTK_Simulator is the script available:
To test a scene it is often necessary to use the headset to move to a
location. This increases turn-around times and can become cumbersome.
The simulator allows navigating through the scene using the keyboard
instead, without the need to put on the headset. One can then move
around (also through walls) while looking at the monitor and still use
the controllers to interact.
Supported movements are: forward, backward, strafe left, strafe right,
turn left, turn right, up, down.

Simulate/Emulate Xbox Controller in C++ or C#

I have a cooperative PC game, but the second player need Xbox joystick to play. Well i don't have Xbox Controller i have some other 10 buck piece of shit joystick and the game don't recognize him.
So i tried different programs to emulate any joystick to XBox joystick, but because mine is cheap the program wont recognize it too.
So i want try to create a program which Simulate XBox joystick inputs.
Then i will capture mine joystick clicks and send the Xbox simulated one. I know how to capture mine joystick clicks i have done that already.
The question is simple - How to send XBox360 Controller inputs to my PC?
If you're forced to use XBOX Controller, i assume you're using XNA
If that's the case, you could try this Wrapper:
http://sourceforge.net/projects/xnadirectinput/

Categories