PUN Rally (multiplayer racing tutorial)

[Released Dec 16th, 2015] – Buy from the Unity’s Asset Store.

So, it’s been a while since the last post, and the reason is that we’ve been really busy with a different project: a complete project/tutorial for the Unity Asset Store.

punrally01

We developed this nice multiplayer rally game, and it’s being released with source code, comments, and an awesome tutorial in PDF. The project uses Photon Unity Network (and Photon Cloud) to provide seamless network connectivity, and Photon has been gentle enough to close a publishing deal with us.

Here are some links, and the project description from the Asset Store:

Discuss the pack in the official forum thread.

free PDF Tutorial

Demos: Win, Mac, Linux

 

Project description:

PUN Rally is a complete base project for a multiplayer racing game using Photon, the most popular network platform for Unity.

Here’s the first video in the tutorial series:


The project includes all sources and a 30+ pages illustrated tutorial book (PDF) explaining its use of realistic physics, dead-reckoning, checkpoint-based positions, and several other important features of multiplayer games, such as lobby control, car-selection and server-synced race-start.

Features:

– Realistic physics based on standard colliders, wheel-colliders and rigidbody;
– Detailed suspension movement;
– Real-time race synchronization over the internet using PUN (Photon Unity Network);
– Dead-reckoning techniques to smoothly deal with latency;
– Server-synced start and grid spawns;
– Checkpoint-based race management (positions, laps, finish, etc);
– Custom car selection (prefabs based) for connected players;

The project is a foundation for a multiplayer racing game, but also serves as a comprehensive introduction to several multiplayer concepts with Photon:

– Dealing with lobbies, rooms creation and joining;
– Managing player connection and disconnection (both in menus and races);
– Using custom player properties;
– Remote Procedure Calls (RPCs);
– Server-based time/clock (for race start);
– The PhotonView component;
– Custom network synchronization of GameObjects;
– PUNBehavior and Photon.MonoBehavior classes;

Simple Unity Game for Free

Last post we showed how we created a MOBA in 24h using Unity, giving the project’s sources for free in the end. The day before we got into that project, we’ve also coded another game for a fast workshop we gave at that time, a very simple maze shooter intended to show how easy one can create a fun and challenging game. We called it Spooky:

Spooky init screen. Can you escape the maze?

Spooky init screen. Can you escape the maze?

We’re also giving this one for free for beginner game developers and programmers who are interested in using Unity for their 3D games.

The game binaries can be downloaded (Win, Mac, Linux), and the project sources can be found on our Github page.

The game was made without the use of any 3D model besides Unity’s basic cubes and a single texture (for bullets). The cubes were coloured and scaled to represent the player (blue), walls (gray) and different enemy types (yellow, orange and red), each one increasingly more difficult to defeat.

Our inspiration came from a youtube video that showed how you can make a fun game using very simple graphics. We made it much simpler than the one in the video, so inexperienced programmers can still understand the code. You can always try to improve it and make it as complex and challenging as the one in the video.

Player, enemies and walls are basic cubes. The player can shoot the enemies (and some enemies do it as well).

Player, enemies and walls are basic cubes. The player can shoot the enemies (and some enemies do it as well).

The game consists of a single level/maze, that is populated by many enemies. The yellow enemies are almost harmless, except if the player touches them, going back to the beginning of the level. The orange and red ones also shoot the player, while the later one includes a screen-shield (meaning it has to be shot twice to be defeated). The enemies are positioned in the maze in order to give an increasingly difficult challenge level for the player.

The maze: besides finding the exit, the player has to defeat increasingly more challenging enemies.

The maze: besides finding the exit, the player has to defeat increasingly more challenging enemies.

The game uses only a handful of different object types, which we stored into prefabs. There’s the player, two bullet types (only the color changes), three enemies and a particle system (bullet explosion/sparks);

Prefabs were used to store the object types of the game.

Prefabs were used to store the object types of the game.

We only needed to write 5 very simple scripts:

  • player movement input;
  • player gun control and input;
  • enemy AI (shared for both enemy types that shoot – orange and red);
  • bullet script (that triggers sparks and object destruction on hit);
  • A test to check for victory condition;
Only 5 scripts had to be written.

Only 5 scripts had to be written.

Besides being just a handful, we made sure the scripts are also very simple to understand, nor having many lines of code, neither using any fancy/magic stuff.

The scripts are very simple to understand, specially tailored for beginner programmers.

The scripts are very simple to understand, specially tailored for beginner programmers.

So, what are you waiting for? Go to our Github page and download Spooky’s project sources and modify it at will. We hope you find it useful.