Unity Pong Multiplayer by manelizzard - 1

Network

Classic pong game with network multiplayer

Unity 5.3.0f4GNU General Public License v3.0Updated 3 years agoCreated on March 24th, 2017
Go to source

Unity Pong Multiplayer

Classic pong game with network multiplayer.

Screenshot

Usage

  • Press SPACE key to start the game. Only the HOST can start the game.

  • Press UP ARROR and DOWN ARROW to move the paddle upwards and downwards.

  • Host player is always spawned on the right field, while client player on the left field.

Implementation

Paddle

The paddle contains a kinematic RigidBody2D with a Polygon2D collider. This polygon enables to build a non-rectangular collider in order to allow the user more flexibility while hitting the ball.

The paddle is moved at a certain velocity and clamped to avoid losing it outside the field.

Class hierarchy

PaddleController is the base class controlling the paddle movement and limitations. Child classes, like PlayerController, enable to specify the control keys (W/S or ARROWS).

Ball

The ball contains a script used to detect collisions (with lose triggers), respawn and inform score manager.

Colliders

Aroud the field there are four colliders:

  • Two for the floor and ceiling, with a Physic2D material bouncing.
  • Two for the left and right walls. These ones are the colliders controlling the scores.

Multiplayer

PongNetworkManager takes care of starting the game when two players are connected (only the host can start the game). The ScoreManager class synchronizes its variables in order to be displayed in both clients, and two prefabs (Ball and Player) are spawned. Player prefab is Local Player Authority in order to allow user control.

Starting the game

One client must start as HOST using the UNet HUD provided, while the other one must connect as a LAN Client. The host IP needs to be provided to the second client to be able to connect.

Future work

  • Create proper art (and resolution) for scores.
  • Fix possible infite loops when ball bounces vertically against the walls.
  • Implement a turn-based game start.
  • Pack all assets in a SpriteSheet and create AssetsBundle in order to download season related assets. Implement particle systems and sound and include them in the AssetBundle.
Show all projects by manelizzard