Technology

Saving Characters from Crossy Road

How a VR game was replicated to train senseless drivers from Crossy Road.

Jolie Li
Intuition
Published in
5 min readFeb 10, 2021

--

The Crossy Road game where players have to tap and swipe the screen to move the character, avoid moving vehicles, and cross rivers.

On November 20, 2014, Mat Hall and his co-developers launched an amazingly successful arcade video game app called Crossy Road. This app earned $10 million in its first 90 days and I jumped on the bandwagon in playing it after I saw my dad kill his first virtual chicken in the game. All my cousins were playing it at that point, and everyone was making “Why did the chicken cross the road?” jokes.

I got some good laughs from the game, but the entire time I was just thinking: “These cars suck at avoiding obstacles.” I mean, they just keep senselessly killing chickens, witches, soccer players, ducks, and even unicorns! As an 8-year-old at the time, I thought it would have made more sense if I drove the cars instead. So now, to whoever has been driving those cars terribly, I replicated a game just for you…

The Ultimate Driving Practice Arena

I replicated the Player Control game from Unity into Prototype Driver:

Demo of the Prototype Driver game.

The player of this game simply has to control the vehicle to rotate or move forward/backward to avoid as many obstacles as they can in order to reach the end of the road (*cough cough* Crossy Road drivers pay attention). Here’s to how I replicated the game:

Putting It All Together

The two main parts to putting this game together were:

  • Being familiar with the Unity editor/workflow
  • Programming C# scripts for player and camera functions

Setting Up the World

A page to get assets to the game from the Unity Asset Store.

My first step was to download and import assets from the Unity Asset store into the Unity editor. When the assets have successfully imported, I created a new scene where the only thing present was the background terrain and a floating road.

Dragging the vehicle and game objects to the scene.

Since everything was empty, I added a vehicle to the scene, which is the player game object, and other obstacles I positioned like crates, rocks, barrels, etc. For every object, I added a rigidbody component so the objects would follow Unity’s physics system, and I could adjust the mass of objects. After dragging, duplicating, dropping, positioning, and organizing many game objects, I positioned the main camera right behind the vehicle at a downward angle. My completed VR world looked like this:

Completed map of Prototype Driver. The little 2D camera floating above the player vehicle is the main camera.

Programming the Main Camera

The main camera on a broader scale.

Unfortunately, this camera can’t move anywhere unless I communicate to the Unity editor that this little guy can be set free to follow the player game object when it moves. I wouldn’t want the main camera to float in the same place when the vehicle will eventually be able to drive away later on. If this happens, the player won’t be able to see much after the vehicle drives away.

A brief script to program the characteristics of the main camera.

To program the camera so that it follows the player game object as it moves later on, I created a new C# script called FollowPlayer and attached it to the main camera in the Unity editor. I then added a public GameObject player to the top of the script so then I could drag the player game object onto the empty player variable in the editor’s inspector to associate the two objects.

I then created an offset variable under the category of Vector3 (a structure used to pass 3D positions and directions around in Unity) which contains the coordinates of the initial player game object. Under Update(), I set the transform position of the camera equal to the sum of the player transform position and offset. This makes sure that every frame updates the camera’s position to follow the player’s movement.

Sitting in the Driver’s Seat

Vehicle and main camera.

This little car can’t do a thing right now. No matter what controls the player presses, it is just a game object that won’t budge.

A script on how the player game object moves based on user input.

In the script, I set up public float variables so I could adjust the speed of the vehicle, how fast the vehicle turns, and so users can change the horizontal/vertical input during the game. Under Update(), horizontal input involves how what the user inputs affect how the vehicle moves left and right. VerticalInput involved how the user input affects how the vehicle moves forward and backward.

For moving forward and backward, I used a translation function to move the player game object like sliding a piece of paper along the y-axis of a graph. For moving left and right, I wanted the car to turn in a smooth way, so I used the rotation function. Notice how within the functions, speed and turn speed are multiples so that I could change the speed in which the car moved forward/backward or turned left/right.

Practice!

Crossy Road characters.

Take a good look at this poor chicken! It’s been squashed and burnt so many times with its buddies that they can’t even afford health insurance anymore. To the Crossy Road drivers out there, spend some time training in Prototype driver so you can stop injuring these innocent characters who just want to cross the road. While they practice on that, I’ll practice making more Unity games and release another one soon.

Thanks for reading! Any feedback, applause, or comments are welcomed. If you found the content enjoyable, follow me on Medium! Feel free to connect with me via email (Jolie837837@gmail.com) and LinkedIn!

--

--

Jolie Li
Intuition

I wrote about my journey in building and learning about rising technology like virtual reality.