Cartoony 3D penalty shootout game made for newspaper website Adressa.no.

Developer
Hållingwood & Lande Audio
Release
2024
Platforms
Web
My roles
Programming · Game Design · Music · Sound Design

The game can be played here.

This project began when we contacted Norwegian newspaper Adresseavisen with an idea to develop a game that would engage their readers. We proposed a small, addictive game; the kind where players want to do "one more round". After a bit of brainstorming, we all agreed that a penalty shootout game would be a good fit for their readers.

Our team consisted of two people.

  • David Skaufjord as project lead, artist and voice actor
  • Martin Lande as programmer, sound designer and composer

Both contributed to overall game design.

A complete round of Straffe, from keeper selection to the final score. August 2024.

Concept

These were our goals

  • The game should run in browsers, both mobile and desktop
  • Gameplay that is easy to learn, but hard to master
  • Online highscores
  • Replay-system
  • Players should be able to customize the keeper

Concept by David Skaufjord.

Execution

We used Unity, FMOD and git. Our tools were Blender, Photoshop and Affinity Designer. Reaper for music and sound design. We collaborated via Discord, as we both work from home.

We quickly decided to go for a 3D environment with a flat 2D keeper. We made use of Unity's native physics system. To invoke an authentic feeling, we used the official FIFA guidelines as reference when modelling the field and the goal.

Field and goal with more or less correct dimensions.

We made the goal posts slightly thicker to make it easier to see what's going on, and to score off the post.

Basic systems

Code-wise, we used a state machine to keep track of the main game-flow. This is handled by the GameplayHandler object, which works as a mediator between most other systems in the game. This allows other systems to be mostly self-contained, which lets us reuse them in other projects without too much work. As an example, the UI system is directly tied to specific game states for transitions between screens.

All GameStates in the game.

Our game systems that need to know the current game state can use this Action. This way, GameplayHandler doesn't need to know about our other systems. This is known as the observer-pattern.

We use Cinemachine to control the camera, which is one of Unity's own packages, available in the Package Manager. It is highly recommended for anyone who hasn't tried it.

The Ball

Our ball is physically based, so all we need to do to simulate a shot is to apply a given force. We add some torque to it based on the player's screw input. The ball continually moves slightly in the direction of its rotation, based on its current direction of travel. As soon as it hits something, we stop this behaviour.

The code that makes the ball "screw". This is applied every frame.

Early on, we had an issue where the ball just wouldn't rotate as fast as we wanted, even after applying extreme torque values. This turned out to be a project setting, under Physics > Default Max Angular Speed. We turned it up to 100 in our case.

We made use of OnDrawGizmosSelected to draw debug visualizations for our various ball physics settings, etc. Here, we're adjusting the possible shot angles.

The Goalkeeper

Our keeper is built up from 2D sprites, which we animate using Unity's own skeletal animation package. We're also using their PSD-importer package, which lets us export all keeper body parts in a single .psd-file. We define a skeleton using the animation package and then generate a mesh that lets us animate and bend his various body parts.

As the player shoots, the keeper goes completely limp, and we hurl the body towards where the ball is likely to end up. Ragdoll physics is always fun, and since both the ball and the keeper are physics-based, we end up with a bit of dynamic gameplay. The hands are dragged towards the ball as well, for a second after the jump. This procedurally generates a somewhat believable animation of a keeper trying his best to catch the ball.

One of our goals was to give the keeper a bit of personality. Before every round, the player can randomize the look of the keeper with various eyes, noses, clothes, etc. Technically, the keeper also has voice acting with two different voices; a man and a woman. Both are acted by Skaufjord.

The keeper is thrown like a ragdoll.

The very moment the shot is taken, the keeper has to know roughly where the ball will end up. Therefore, we had to write our own little physics system that can simulate the ball's trajectory in an instant. One advantage here is that we don't need the exact location; just a rough estimate. Luckily, Unity has native functions for testing collisions using a given shape at an arbitrary location.

The thin red line shows where the keeper thinks the ball will go. Yellow spheres show the ground truth.

UI

Every screen is its own object, controlled by a MenuController. This component handles transitions between them, which makes it easy to add or remove screens as needed throughout the development of the project. Procedural transition animations make use of Robert Penner's easing functions.

The player immediately gets feedback on how their shot went. Afterwards, a detailed point breakdown appears. We tried to make this experience as juicy as possible, using bespoke animation and sound design. At the same time, it shouldn't be a chore to watch every time, so it shouldn't overstay its welcome. Visuals and audio are inspired by Nintendo's typical style of UI.

Replay system

The player gets to see a replay of their last shot, as soon as the result of the shot is known. This mirrors real football, where you often see a replay in slow motion from various camera angles. Since Unity's physics system is not deterministic, we would either have to write our own physics system, or use a system where we store the position and rotation of any objects included in the simulation. We opted for the latter, which is usually described as a state-based approach.

The system we ended up with has a list of transforms; the ball and all body parts of the keeper. The position and rotation of all objects are noted continually, every four fixed frames. This recording happens as soon as control of the ball is given to the player, and ends about a second after the result of the shot is known. Afterwards, we trim the beginning of the replay down to just before the shot was taken. We also set a maximum frame count to keep the replay from getting too large, should something unexpected happen.

When playing back the replay, we interpolate between the values of our recorded transforms to make it look natural, and then use Time.timeScale to apply slow motion.

Highscore system

After a round is complete, the player gets the opportunity to enter their name and send their score to a public leaderboard. An interesting challenge here is that players can write anything, including swear words. The name is checked against a pre-written text file full of bad words. If a bad word is detected, the player is prohibited from sending their score.

An SQL database is used to keep track of scores. The game comunicates via a few PHP scripts, which in turn talks to the database and passes information back to the game. We make use of UnityWebRequests to communicate with the server.

During testing, we discovered that the WebGL platform requires special handling to be able to use web requests. Since our game runs in the browser, the response from the server must contain properly configured CORS-headers. Our test server did not let us configure this, but fortunately we can hard-code them into our responses.

Hard-coded headers added to our server responses. While testing, we allowed any origin - but this should be set to something more restrictive in a final build.

The leaderboard shows the best rounds of the last seven days.

We experimented with cloth physics, but ended up cutting it to ensure good performance on mobile.

Sketch of the audience members by Skaufjord.

I used Affinity Designer to make 2D assets like our UI and logo, and for final exporting of David's keeper and audience.

Browser implementation

While certain things in the game are hardcoded in our scripts, Adressa needed to be able to swap out some of the content. For example, the ad posters behind the goal, or the share-URL that appears when players try to share their game on facebook or twitter.

To achieve this we made use of the special StreamingAssets-folder, the contents of which can be altered after a build is created. These assets are loaded during runtime. In a WebGL-build, this folder is located on the server, which means we actually need to load them using a WebRequest - like any other remote file.

Summary

The technical aspect of the project took just over 100 hours to complete, spread out over a two-month period. This went rather smoothly, in part due to a cautious approach to scope. After the newspaper implemented the game on their website, we discovered a few bugs. They also requested a few changes. Fortunately, we had predicted these things, and was able to quickly fix them.

These were a few of the notable technical difficulties of this project:

  • We used Unity version 2022.3, which doesn't officially support WebGL on mobile. This led to some trouble, especially pertaining to audio. For example, the sound cuts out if you switch to another tab on mobile. We couldn't find a reliable way to detect this. Unity 6 has official support, which likely would have made this easier to handle.
  • We came across a bug in the 2D Animation package, where certain SpriteSkin components would get stuck. For example, the keeper's head would stay put in the center of the goal, while the headless body would move towards the ball. Luckily, we were able to fix this by modifying the package files.
  • As the game supports both portrait mode and landscape mode, we had to take special considerations when designing the layout of the UI. For example, if we have three buttons covering the width of the screen in a way that looks nice in landscape mode, this would be a cramped layout in landscape mode. Setting the Canvas component to scale equally by width and height helps. Additionally, we made a script that lets us check what mode we're currently in to dynamically change the layout in a few edge cases.

More articles

Explore the full portfolio