Network

Multiplayer FPS

Multiplayer-FPS

PRs Welcome License: MIT Template from jarvis

A multiplayer first-person shooter game based on Unity3D. Different types of input devices are supported to improve game experience, including Kinect, Xbox controllers, Leap motion, and VR Glasses. (Each contained in a different branch)

Game logic and functionality

  • Login panel

    • Input your player name and the room name you want to join
    • Click ‘join or create room’ button to join a room or create a new room
    • The network connection state shows on the bottom left corner img
  • Game interface

    • Player’s HP on the top left corner
    • The message panal on the bottom left corner, which shows status of other players (e.g. dead or respawn)
    • A gun (AK-47) will always appear on the bottom right corner in front of every thing you can see
    • A red shooting sight is always in the center of the screen
  • Player models

    • There are three types of player models:

      • Policeman: a policeman-like model with yellow skin
      • RobotX: a robot-like model with dark pink skin
      • RobotY: a robot-like model with dark blue skin
    • Animations:

      • Walk towards four different directions
      • Run towards four different directions
      • Jump without affecting upper part body (achieved by unity3d body mask)
      • Shoot without affecting lower part body (achieved by unity3d body mask)
      • All the original models and their animations can be found from Mixamo, which is a pretty good game model website run by Adobe
      • Unity Blend Tree
        • This is used to make the player walk or run more naturally. It uses interpolation function to map different combinations of user input to different animations.
        • img
    • State Machine

      • There are multiple layers in the player state machine.
  • Player movement

    • Walking && Running && Aiming
    • Jumping
    • Dying
  • Gun model

    • The original gun model (AK-47) was from Unity Assets Store
    • Shooting animation are added by setting keyframes in unity3d animation panel img
  • Networking

    • This game uses Photon Unity Networking, which is a good network model from Unity Assets Store
  • Bullet effects

    • Bullets hitting different materials will cause different effects
      • Wood
      • Ground
      • Metal
      • Concrete
      • Water
  • Door animation

    • Doors will automatically open when there is someone nearby and close when no one is around
    • Before opening
    • After opening

Script files

  • CameraRotation.cs
    • Rotates the scene camera in every updated frame
  • DoorAnimtion.cs
    • Controls the door animation and detect if the player enters or exits the door triggering area
  • GunFirstPersonView.cs
    • Controls the first person view of the gun shooting animation
  • GunShooting.cs
    • Controls the gun shooting action on the network domain. The shooting function will evert the client if necessary
  • IKControl.cs
    • Ensures the model is holding a gun regardless of movements or rotations
  • ImpactLifeCycle.cs
    • Destroys the bullet object after several seconds to save CPU time and memory
  • NameTag.cs
    • Displays other players’ names above their heads in a local game
  • NetworkManager.cs
    • Controls the whole network connection
  • PlayerHealth.cs
    • Calculates and updates health points of each player
  • PlayerNetworkMover.cs
    • Synchronizes the position of the player among different clients
  • ShowName.cs
    • Displays the players’ names above their heads
  • WeaponPos.cs
    • Positions the gun towards the player’s hands

Input Devices

  • Mouse and keyboard
    • The traditional way
    • Cheap and easy to use
  • Kinect
    • See below for details
    • This part was implemented by my friend Ruochen Jiang, many thanks to him!
  • Xbox Controller
    • Like the combination of mouse and keyboard
    • Most Xbox games use this way to play
  • Leap Motion
    • User hand gesture to control game
    • A more advanced interaction that might become popular in the future
  • VR glasses
    • More vivid and closer to reality
    • Recently very popular but devices are most likely expensive
    • Players cannot move now due to the limitation of my device

Kinect Details

  • Tools and Platform:

    • Kinect for Xbox One
    • Kinect for Windows SDK
    • Unity
    • Visual Studio
  • Recognition Method:

    • Use Kinect for Windows SKD (BodySourceManager) to get the positions of the player’s skeleton. Determine the actions of moving, jumping, shooting based on these positions and regard rotation as an input of the game.
  • Shooting

    • Users lifting their right arm will trigger shooting in the game. The game calculates the distance between the user’s right hand and right shoulder based on skeleton nodes. Shooting will be triggered if the calculated distance reaches a threshold.
  • Moving:

    • Move in the game by stepping forward, backward, leftward, and rightward. The game recognizes moving actions by the offset of right foot’s skeleton node on x-z plane. A movement will be triggered if the offset reaches a threshold.
  • Jumping:

    • Users can jump in the game. The game calculates offset of right foot’s skeleton node on the z-axis to register a jumping action. Jumping will be triggered if the calculated offset reaches a threshold.
  • View Rotation:

    • Use your right hand as a virtual mouse to control the camera rotation. The game records the initial position of the left hand as the initial position of the mouse, then calculates the camera rotation by the left hand’s offset.

Contribution

See CONTRIBUTING.md

License

MIT License