- Before You Start
- 3rd Party Assets
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.
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
|1.1.3||Dec 05, 2022||Fusion Golf 1.1.3 Build 5|
- 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
The main Scripts folder
/Scripts has a subfolder
Networking which contains scripts whose primary function is interfacing with Fusion.
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 are players who have explicitly chosen to watch rather than participate in the game. A spectator's
PlayerObject will never have a
The flow and behaviour of the game logic is controlled by the
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:
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.
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:
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.
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.
Input is polled by
PlayerInputBehaviour.cs into the custom
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
Anglein which the player is facing This data is processed by the
Putterplayer script and facilitates, in addition to putting the ball, both the local player and spectators seeing the appropriate UI.
Players are handled in 2 parts:
PlayerObject- contains the
PlayerRefvalue 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
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:
- Skybox Extended Shader by BOXOPHOBIC
- Kenney's Minigolf Kit by Kenney
- Toon Water Shader by Erik Roystan Ross
- Low Poly Cliff Pack by Broken Vector
- Low Poly Tree Pack by Broken Vector
- Fredoka One font by Milena B Design
IMPORTANT: To use them in a commercial project, it is required to purchase a license from the respective creators.