Building Multiplayer Games (w/ Unity)

45
MULTIPLAYER MOBILE GAMES (UNITY)

Transcript of Building Multiplayer Games (w/ Unity)

Page 1: Building Multiplayer Games (w/ Unity)

MULTIPLAYER MOBILE

GAMES (UNITY)

Page 2: Building Multiplayer Games (w/ Unity)

Hello!MY NAME IS NOAM GAT

CTO @ Tacticsoft

We make strategy MMOs

And you are?

Page 3: Building Multiplayer Games (w/ Unity)

1MULTIPLAYER GAMES

Definition and scope

Page 4: Building Multiplayer Games (w/ Unity)

“A multiplayer game is a game

played by multiple people”

- Captain Obvious

Page 5: Building Multiplayer Games (w/ Unity)

HOWEVERThere are several criteria to

distinguish between them, with

technical consequences.

Page 6: Building Multiplayer Games (w/ Unity)

Local (Single Device)

Badlands

King of the Opera

HOW DO THE PEOPLE PLAY THE SAME GAME?

Network

World of Warcraft

Clash of Clans

Hearthstone

Fifa ?

Page 7: Building Multiplayer Games (w/ Unity)

THIS (TECHNICAL) LECTURE IS ALL ABOUT NETWORKED

▪ Local Multiplayer is awesome

▪ IMO very unexplored territory

▪ But it is technically equivalent

to a single player game

Page 8: Building Multiplayer Games (w/ Unity)

Turn Based

Chess

Hearthstone

HOW OFTEN ARE PEOPLE UPDATED?

Real Time

World of Warcraft

Quake

Fifa

Clash of Clans?

Page 9: Building Multiplayer Games (w/ Unity)

Clients (P2P)

Old games

WHO RUNS THE WORLD?

Servers

New games

Page 10: Building Multiplayer Games (w/ Unity)

WHY DID P2P ARCHITECTURES FALL OUT OF FASHION?

▪ Servers are cheaper

▪ Less connectivity issues (port

forwarding etc)

▪ Easier to prevent cheating

▪ If one of the players has the

authority, it is called a server.

Page 11: Building Multiplayer Games (w/ Unity)

2MULTIPLAYER CHECKLIST

Building blocks for most

multiplayer games

Page 12: Building Multiplayer Games (w/ Unity)

MULTIPLAYER FLOW

Match

Conclusion

Lobby

Page 13: Building Multiplayer Games (w/ Unity)

LOBBY

▪ Devices don’t know about each

other yet

▪ They come to a central place and

get grouped to each other

▪ Not the most interesting of tasks

▪ Don’t reinvent.

Page 14: Building Multiplayer Games (w/ Unity)

MULTIPLAYER FLOW

Match

Conclusion

Lobby

Page 15: Building Multiplayer Games (w/ Unity)

MATCH

▪ One central entity (Server) is in

charge of the PERSISTENT GAME

STATE

▪ The clients send actions to it,

it notifies everyone of changes

to the world

▪ The server can be one of the

clients.

Page 16: Building Multiplayer Games (w/ Unity)

PERSISTENT GAME STATE?

The compact representation of the

game’s state. (The Model of MVC)

▪ Chess ? Game board

▪ FPS ? Player positions, stats

The clients have to be able to

build their perspective of the game

from it.

Page 17: Building Multiplayer Games (w/ Unity)

SINGLE AUTHORITY FOR EACH OBJECT

Make sure not to have two entities

in charge of the same object

▪ Character owned by client

▪ Projectiled owned by server

▪ Environment simulated separately

Multiple management causes desyncs,

flickers and unnecessary overhead

Page 18: Building Multiplayer Games (w/ Unity)

ACTIONS AND CHANGES

The client has to notify the server

of its actions. It can do so in

several ways:

▪ State updates (I am in X=1,Y=4)

▪ State deltas (I moved up)

▪ Actions (Jump)

The client has to update from the

server. Not always symmetric.

Page 19: Building Multiplayer Games (w/ Unity)

State Based

Robust

Simple

TRADEOFFS

Delta / Action Based

Secure

Compact

Cheap

Page 20: Building Multiplayer Games (w/ Unity)

Game

Conclusion

Lobby

Page 21: Building Multiplayer Games (w/ Unity)

Conclusion

In case of a metagame, server

updates “the bookkeeper” of the

match results.

▪ High scores

▪ Rankings

▪ XP

The bookkeeper is often the lobby.

Page 22: Building Multiplayer Games (w/ Unity)

3UNITY MULTIPLAYER

Let's build stuff.

Page 23: Building Multiplayer Games (w/ Unity)

Many different possibilities

▪ WWW Class (HTTP requests)

▪ Legacy Unity Networking

▪ UNet (New in Unity 5.1)

▪ Asset Store (Photon, Parse etc)

Page 24: Building Multiplayer Games (w/ Unity)

Many different possibilities

▪ WWW Class (HTTP requests)

▪ Legacy Unity Networking

▪ UNet (New in Unity 5.1)

▪ Asset Store (Photon, Parse etc)

Page 25: Building Multiplayer Games (w/ Unity)

UNet

Page 26: Building Multiplayer Games (w/ Unity)

UNet

Latest in-house evolution of Unity’

s networking efforts.

Lets you select which GameObjects

to synchronize, and how.

Page 27: Building Multiplayer Games (w/ Unity)

UNet (1 of 4)

Create a

NetworkManager.

Select Offline

(Lobby), online

(Match) scenes and

per-client Prefab.

Debugging Lobby

GUI

Page 28: Building Multiplayer Games (w/ Unity)

UNet (2 of 4)

Create a

NetworkIdentity.

Decide who takes

care of this

network-synced

object, and how

data is

transferred.

Page 29: Building Multiplayer Games (w/ Unity)

UNet (3 of 4)

Manage objects.

Enable / disable

components based

on whether the

client controls

this instance of a

player.

Page 30: Building Multiplayer Games (w/ Unity)

UNet (4 of 4, optional)

Manage sync.

Smoothly

transition between

state snapshots

rather than pop

between them.

Page 31: Building Multiplayer Games (w/ Unity)

UNet Video Tutorials

gamertogamedeveloper.com

21 episode long video tutorial of

creating a project with UNet.

Includes source code of final

project!

Page 32: Building Multiplayer Games (w/ Unity)

Legacy Warning

Legacy Unity Networking and UNet

don’t mix! Check documentation to

make sure you are using consistent

components.

Page 33: Building Multiplayer Games (w/ Unity)

Parse

Page 34: Building Multiplayer Games (w/ Unity)

Parse

A “Backend as a Service” owned by

facebook.

Not created just for game

development, but is useful in this

domain.

Page 35: Building Multiplayer Games (w/ Unity)

Parse (1 of 3)

Create objects.

Page 36: Building Multiplayer Games (w/ Unity)

Parse (2 of 3)

Retrieve objects (from the same

client or others).

Page 37: Building Multiplayer Games (w/ Unity)

Parse (3 of 3)

Query objects (from the same

client or others).

Page 38: Building Multiplayer Games (w/ Unity)

Parse

A simpler and slightly less “Unity-

ish” solution.

If you can define your multiplayer

layer as database interactions,

this is be a very simple way to

approach it.

Page 39: Building Multiplayer Games (w/ Unity)

Parse

Very well documented SDK.

Costs money to scale up, but has a

generous free offer that you won’t

pass until you have MANY users.

Page 40: Building Multiplayer Games (w/ Unity)

4HACKATHON TIPS

Let's build stuff.

Page 41: Building Multiplayer Games (w/ Unity)

AIM FOR THE SUNNY SCENARIO

Robust multiplayer

handling is hard.

Assume everything

with the connection

is fine.

Page 42: Building Multiplayer Games (w/ Unity)

FORGET ABOUT SECURITY / CHEATING

Its OK to give

clients more than

they need to know if

it makes things

easier for you.

For now.

Page 43: Building Multiplayer Games (w/ Unity)

GET THE NETWORKING POC DONE QUICK

Think of the

solution that suits

your game.

Get to a point where

two clients share

data ASAP.

Page 44: Building Multiplayer Games (w/ Unity)

LOVE THY NEIGHBOUR

You will share

similar difficulties

with the other

groups.

Use the power of the

group to solve

things faster.

Page 45: Building Multiplayer Games (w/ Unity)

Thanks!ANY QUESTIONS?

You can find me at:

@noamgat

[email protected]