Project time

5 months

Team size

Tags

Racing game Hover vehicles Physics engine Racetrack tool Solo project

Tools

UE4 Blender Photoshop Unreal Blueprints

Hover Racer

Introduction

Hover Racer was my fourth-year project, in which I tried to create a hovering vehicle racing game similar to Wipeout or F-Zero. I built this project using UE4 and Blueprints. In UE4 I built a race track creation tool and a deterministic physics engine for this project.

What I learned

  • I improved on my knowledge of the UE4 construction script.
  • I learned more about splines.
  • I learned a lot about 3D vector math.
  • I learned how to build a deterministic physics system for hover vehicles.
  • I thought myself the program Blender.

Development

Looping the racetrack

For my game, I wanted to add roller-coaster like loops and corkscrews to the race track. I had not foreseen the tremendous difficulty I would face making the race track able to loop. The issue was that when the track went past the 90° mark the race track would twist around itself.

The race track is built from a 3D spline. A spline is a curve that goes between points using tangents like the pen tool in photoshop. The track then gets build along this spline using multiple spline meshes. A spline mesh is a 3D mesh that deforms and follows its own spline with only two points.

The problem of the twisting was caused by UE4’s rotation system which rolls 180° when the pitch goes past 90° and sets the pitch to -90°. This works fine most times. However, the race track uses spline meshes which follow a spline and its rotation including the 180° roll. The problem only exists for the roll since for the pitch and yaw the spline’s tangents are used.

I tried to adjust for this extra roll, by setting the end roll relative to the start roll of the spline meshes. However, this still caused the race track to twist halfway before twisting back. To fix the problem I had to change the up vector of the spline mesh so it did not need to calculate past the 90° pitch point. However, now I had a new issue. I needed to find the roll relative to the new up vector. I got the roll by getting the up-vector at points along the spline instead of its rotation and calculate the roll from these vectors.

Physics engine

I went for an arcade racing feel but the vehicle would behave strangely when changing the velocity directly. I tried to rotate the velocity with the vehicle but while I was adjusting the velocity the vehicle would stutter. In hindsight, this was probably due to physics sub-stepping and I could do it using C++.

However, since hindsight is late, I created my own physics engine inside unreal instead. The physics engine just needed to work for the hover vehicle since it was the only object using physics. I had learned a lot about physics engines trying to beat Unreal’s physics engine to my will.

Creating my own physics engine also freed me to make the physics deterministic free from the framerate. Unreal uses a frame sub-stepping system for their physics. Which means the physics tick rate is still influenced by the render tick rate of the game.