PID Controllers in Unity3D

This post will cover the use of PID controllers in video games.

If you’ve ever used your car’s cruise control, flown a quadrocopter, or piloted a rocket, then there’s a good chance that you’ve used a PID controller. A PID controller is a type of control loop that’s used for automation.

PID controllers are flexible since they can handle changing target values and changing external conditions. The PID can be configured by it’s designer to respond to changes in different ways. For example, one system might respond with fast, snappy movements, while another uses slow and gentle movements. Both can be achieved just by reconfiguring the PID controller.

The beauty is in it’s simplicity

Read more

Drawing Mushrooms with Vulkan

There’s a niche genre of music on the internet called “oscilloscope music”. This is electronic music that is designed to be visualized with an oscilloscope. Music visualizers have existed for a long time, but they often just display an image that represents the audio abstractly. Oscilloscope music allows the musician to draw arbitrary shapes using sound.

Read more

Creating a Flight Simulator in Unity3D Part 3: Weapons and AI

Now that we have the flight mechanics and HUD, we can start working on the weapons and AI. The AI will have all of the same capabilities and limitations as the player. It’s plane will have identical stats and it will use the same weapons.

The AI will be simple, but still capable of shooting you down. It will have logic for aiming and using it’s weapons optimally, for avoiding the ground, and for maintaining a reasonable amount of energy.

Read more

Creating a Flight Simulator in Unity3D Part 1: Flight

I’ve been playing Ace Combat and Project Wingman recently. This inspired me to write my own flight simulator using Unity3D. I wanted to make a flight sim with more depth than the arcade flight sims, while still being accessible.

You can think of realism as a spectrum. On one end is Ace Combat and at the other is more serious sims like Digital Combat Simulator. While researching I found Tiny Combat by Why485. This game sits somewhere in the middle of the spectrum, which is basically exactly what I want. The game requires the player to understand concepts like energy management without needing several semesters worth of classes to get the plane off of the ground. It’s got a pretty slick art style too.

So I set out to make my own. Here’s a demo based on what this blog series will cover:

This post is also available in video form: https://www.youtube.com/watch?v=7vAHo2B1zLc

Read more

Reflex Sight Shader in Unity3D

In this post, I will describe a shader for Unity3D that recreates the look of a reflex sight. A reflex sight projects the image of it’s crosshair to some distance in front of the viewer. Red dot sights holographic sights are both types of reflex sights, they only differ in the crosshair used for aiming.

The distance of the crosshair may be finite, such as 100 meters, or it may be infinite. When you move your head side to side, the crosshair will appear to be in the distance. It does not look like a red dot painted on the glass. This video is an example of the effect in real life.

There are multiple ways to achieve this effect. One method is to use a separate object for the crosshair and use stencil masking so that it only draws it behind the lens. However I don’t like the idea of using two objects or using the stencil buffer for a minor effect.

My solution was to use a single object (the lens) and a shader effect to change the UVs of a crosshair texture. This is much simpler to implement. The resulting shader acts like a reflex sight focused to infinity.

The code is available at this Github repo.

The target is 100m away

Read more

Procedurally Generated Dungeons

I’ve been playing some roguelikes recently, so I wanted to try writing my own procedural dungeon generator. There are a lot of different ways to approach this problem, but I eventually decided to base mine off of TinyKeep’s algorithm, described here. I extended the algorithm to work in 3D, to create dungeons with multiple floors.

The code for this example is available in this Github repo. I’m using Unity3D for this demonstration, but these concepts are, of course, usable in any game engine.

Read more