- Home /
Android device as controller for local mulitplayer game,Android device as remote LAN Controller
Hi there.
My goal is to create a local-multiplayer game over WIFI. The game will run on one device (server). This device shows the playing field with the player characters moving around and projectiles and whatnot.
The Android devices connecting to the server (the clients) are supposed to only show an analog stick and some buttons.
How do I get the input from the Android devices to the server?
Right now I use the HLAPI and two cameras. If you're a client only the UI is shown, but in the background the game is running. That seems inefficient.
Answer by BruceKristelijn · Nov 19, 2018 at 10:54 AM
I cannot help you in a futher detail, but you can create functions as commands for the server to get called by every client like MoveForward, MoveRight etc.
https://docs.unity3d.com/ScriptReference/Networking.CommandAttribute.html
This way is a goo way to tell te server to do specific things and you can even do server side calculations and checks to prevent cheating. A quick way to prevent rendering of the scene is to make the camera only render UI elements. This is not the best way to prevent the running of the game in the background but already helps with the intensity of rendering done.
Thank you for the answer!
The command I have works so far (for shooting), I am just wondering if I can send only the input (like the value of axis "Horizontal") and then have the server only calculate the position of the corresponding player.
Basically like a wireless game-controller, but from an Android device and with networking, so I can send something to the controller (like status effects that won't allow the virtual joystick to move)
You can send input to the server via a command.
//Server side command: [Command] void CmdHorizontal(float amount){ //Calcuate funcitonality } //Client side: void Update(){ float horiontal = Input.GetAxis("Horizontal"); if(horizontal != 0){ CmdHorizontal(horizontal ); } }
Please note this code is from the top of my head so it will propably not work directly but you can get the idea. Just make sure to not send an command every update (Thats why i check if horizontal axis is not 0)
! NOW I got the idea. Perfect, thank you :)
Probably wont be as straight forward, but at least it's going foward!