fusion | v1 switch to V2  

Fusion Golf

Level Intermediate

Overview

The Fusion Golf sample demonstrates an approach on how to create an arcade golf racing game with a focus on physics, using a server authoritative, client predicted model. It features a session browser as well as direct connecting via room codes. Hosts can modify various game settings such as max time per hole, max shots, whether or not players will collide with one another, and if the session is visible in the session browser. The sample has an 18 hole course with various physics-driven objects such as cannons, spinners, boost tunnels, and elevator platforms.

Back To Top
 

Before You Start

To run the sample, first create a Fusion AppId in the PhotonEngine Dashboard and paste it into the App Id Fusion field in Real Time Settings (reachable from the Fusion menu). Then load the Menu scene in the Scenes folder and press Play.

Back To Top
 

Download

Version Release Date Download
1.1.6 Apr 12, 2023 Fusion Golf 1.1.6 Build 164

Back To Top
 

Highlights

  • Full networked game state system (pre-game, intro, play, outro, and post-game)
  • Spectating other players
  • Customizable game settings (collision, number of holes, max shots, max time)
  • Synchronized state of objects in the world
  • Lobby Browser (and the ability to make rooms private)
  • Physics focused objects (cannons, spinners, elevator platforms, boost tunnels)
  • Customizable player visuals (RGB Sliders)
  • Region settings, nickname setting, graphics options

Back To Top
 

Project

Folder Structure

The main Scripts folder /Scripts has a subfolder Networking which contains scripts whose primary function is interfacing with Fusion. Notable scripts:

Back To Top
 

PlayerRegistry

The PlayerRegistry stores a reference to each player in the room, and provides utility methods for counting, selecting, and performing actions on one or many players. The default behavior of the utility functions is to ignore players who are spectators, but will operate on the full collection of players if the includeSpectators parameter is true.

Spectators

Spectators are players who have explicitly chosen to watch rather than participate in the game. A spectator's PlayerObject will never have a Controller assigned.

Back To Top
 

GameState

The flow and behaviour of the game logic is controlled by the GameState NetworkBehaviour. GameState defines an enum of the phases of the game, which the networked StateMachine property uses as its states. StateMachine<T> defines a StateHooks class with 3 fields: onEnter, onExit, and onUpdate. When using the StateMachine class, each enum state may have StateHooks defining what happens upon entering, exiting, and while actively staying in the state.

Back To Top
 

Getting Into A Game

Users can host or join a session using either the session browser or directly via the session code. Entering a session code is optional if the user chooses to host, as it will be generated automatically if left blank. Once in a session, the code will be displayed at the top of the screen.

The session code is accessed via: runner.SessionInfo.Name

Back To Top
 

Region Selection

Before choosing to host or join, users are presented with a dropdown to select which Photon Cloud region to use. The dropdown options have been selected as per the Regions Documentation.

Back To Top
 

Matchmaker

Hosting, joining, and the session browser are all handled by the Matchmaker class. It serves as a wrapper for the NetworkRunner.StartGame method and, in the event of a connection error, forwards the error to the DisconnectUI to be displayed to the user.

Back To Top
 

Handling Input

Input is polled by PlayerInputBehaviour.cs into the custom INetworkInput struct PlayerInput. Input in this sample consists of only clicking and moving the mouse. PlayerInput is relatively simple, and contains only 3 fields:

  • isDragging - whether the player is holding down their mouse button
  • dragDelta - how much the player's mouse has been dragged downward
  • yaw - the Angle in which the player is facing This data is processed by the Putter player script and facilitates, in addition to putting the ball, both the local player and spectators seeing the appropriate UI.

Back To Top
 

The Player

Players are handled in 2 parts:

  • PlayerObject - contains the PlayerRef value this object is associated with, a reference to the player's controller (Putter), index in the room, nickname, selected color, and gameplay data relating to score
  • Putter - responsible for responding to input for physics and UI

Back To Top
 

3rd Party Assets

The Golf Sample includes several assets provided courtesy of their respective creators. The full packages can be acquired for your own projects at their respective site:

IMPORTANT: To use them in a commercial project, it is required to purchase a license from the respective creators.


To Document Top