It has been a while since I posted anything about the tech in Retrobooster. Lately, I have been refining the conveyor beams, which figure prominently near the end of the game. They are basically tubes of energy that pull game entities around the levels. Think of them as rivers of space. I imagine them as the main mode of transportation used by Retrobooster’s evil aliens in and around their giant spacecraft.
The motivation for the conveyor beams is to have a fun game mechanic that ties together the final set of levels and builds upon mechanics encountered earlier in the game. The beams allow for new scenarios, such as accelerating faster that you can with your ship’s thrusters, using force fields to bounce in and out of beams, and requiring you to fly at high speeds to penetrate against the flow of a beam.
Making the conveyor beams function properly was a difficult exercise in math. The beams are defined by a series of points. Each point has an associated velocity. From the velocity you know the direction the beam should move and how fast it should push entities inside of it. The curve between two points is defined entirely by the position of the points and the direction vector (normalized velocity vector) at each point.
First I tried to shape the curves with third-order polynomials. Unfortunately, these cannot define perfectly circular arcs. There are a lot of radial levels in Retrobooster with circular walls, so it was necessary to have beams that could follow along those walls. I was actually able to approximate 90- and 180-degree arcs fairly well with polynomials, but s-curves were misshapen. After this failed experiment, I switched to interpolating between real circular arcs. These require more computation to work with, but they are exactly circular when you need them to be and they produce smooth s-curves as well. To define a curve with circular arcs between two points I first create two arcs, one defined by both points and the first point’s direction vector, and the other defined by both points and the other point’s direction vector. Then I interpolate between both arcs depending on the proximity to each point. (Not coincidentally, this method of defining curves is also used to shape the terrain in all the levels.) (Here is a more detailed treatment of splines vs. circular arcs.)
On top of defining the shape of the conveyor beams, there was plenty of work required to make the beams properly influence game entities’ movements. I wanted to allow freedom of movement sideways through beams, make it impossible to push against beams of a certain speed without a running start, allow players to fly faster than beams if they want, and have entities’ velocities rotate as they move along curved beams. This all comes down to a whole lot of tricky linear algebra. The most difficult part was finding a good way to rotate an entity’s velocity as it moves along a beam when the entity is not in the center of the beam. Doing it at the center is easy–off to the side is strange.
Another thing that would have been fun to try is to program the beams as actual inertial coordinate systems. In this scenario, an entity could be moving along with a conveyor beam but its internal velocity vector would be set to zero. In other words, the entity would think it was stationary but they space around it (the beam) would be moving through the game space. The reason I did not program the beams this way is because I predict two problems. One, there would be a discontinuity in an entity’s velocity as it moved in or out of a beam, and two, an unreasonably fast beam would be required to prevent a player from thrusting upstream through it.
For the conveyor beams’ appearance, I wanted some attractive sci-fi graphics that defined the shape of the beam for the player and didn’t distract too much from the rest of the game action. This took a few iterations. Eventually, I settled on what you see in the video. Before that I tried drawing different tubes and amorphous blobs moving through the beams with various shaders and different amounts of glow. These other ideas all looked too polygonal or failed to show the shape of the beam as well as the final solution.
To polish off the visuals, I added some light sources and sound effects to add more pizazz to the energy bolts zipping along the beams.
The conveyor beams function quite well now and look kinda sexy. It’s time to put them into more levels. So far I have a few sketches and prototypes and two nearly complete levels that use the beams. Those levels both have the player manipulating force fields and teleporters while traveling at unsafe velocities. I’ll be refining some of my other ideas in the coming weeks.