Challenge: Ghost Racer

Tutorial

·

intermediate

·

+10XP

·

30 mins

·

(17)

Unity Technologies

Challenge: Ghost Racer

Your challenge is to build a ghost racer for the Hover Racer project. A ghost racer replays the user’s current best run using input that was recorded during that run. It overlays the "real" Hover Racer without colliding with it, producing the effect that the player is racing with a ghost ship.

Languages available:

1. Get Ready

Start by doing one of the following:

  • Load a Hover Racer project from a previous lesson in this course that has been migrated to Unity 2018 LTS

    OR
  • Download, unzip, and open the project Hover Racer 2018 LTS using the link above.

Then import the additional assets in the file Hover Racer Ghost Racer EXTRAS using the link above.

2. Make the Ghost Racer

  1. Create a new physics scene.
  2. Create a Prefab Variant of the Hover Racer ship, and modify it to be visually differentiable from the main ship.
  3. You want the only visible object in the scene to be the ghost version of the ship, but you also want to include the colliders of the environment, so copy across the environment objects but disable them in the Inspector to make them invisible. Because there are a lot of rocks, a variant of the rocks with only the colliders enabled is available in the RocksColliders object included with the “extra” assets, under Prefabs > Environment.
  4. Don’t forget to add the necessary code that loads the physics scene.
  5. For the new physics scene to work with the project, name and add your new replay scene to the Build Settings (Figure 01).
Figure 01: ReplayScene added to build settings

Figure 01: ReplayScene added to build settings

3. Enable Replay Functionality

To integrate with the project script that enables the replay functionality, you need to:

  • In the Main_Complete scene, create a new empty GameObject, and add a Replay Loader component to it. In the component, set Replay Scene Name to the name of your replay scene, as it appears in the Build Settings, not including the path.
  • In the new scene, add a Replay Player component to the ship, and remove the Player Input component.
  • Add a Replay Recorder component to the main racer.

The project contains some built-in code that applies the casting methods used in Hover Racer.

4. Final Result

When you're finished, you should be able to replay your best Hover Racer run along with your current run, to look something like this:

You can download our final project in the file Hover Racer Ghost Racer FINAL linked above.

Complete this tutorial