Coder Social home page Coder Social logo

unity-pong-multiplayer's Introduction

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.

unity-pong-multiplayer's People

Contributors

manelizzard avatar

Stargazers

Mariano Rodriguez avatar  avatar Syarif Abdurrahman avatar PsychoSTS avatar  avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.