Yesterday I worked on the control scheme for Dragon Attack. In its original version, Glauron, the mechanics are very simple:
- Horizontal speed is constant.
- Vertical speed is affected by gravity as usual.
- When you tap, a fixed amount of speed is added to the vertical speed over the next half second or so.
This is almost as simple as in Flappy Bird; the only difference is that the vertical speed boost isn’t all delivered at once (which would make for very jerky movement). The similarity is why Glauron has also been jokingly called “Flappy Dragon” (including by me).
But I wanted something more sophisticated, something which gives you more control, while keeping much of the simplicity. Something that is easy to learn, but hard to master. I wanted to let you swoop down from high up, building speed so your fire reaches farther, but of course running a greater risk of crashing into the ground.
So instead of just tapping, I came up with the following control scheme:
- If you do nothing, you just follow a ballistic trajectory like before. Flying is hard work, yo.
- Tap to flap your wings, as before. However, instead of affecting just your vertical speed, you get a bit of forwards speed as well (“forwards” being “along your current velocity vector”).
- Tap and hold to glide. Drag up and down (like a joystick) to control your pitch. Drag up to curve upwards, down to curve downwards.
Naturally, it took a lot of tweaking to get this even remotely right. I started by looking up how real dragons fly. There seems to be little to no literature on the subject, so I used bird and aeroplane flight as a proxy instead. That turns out to be pretty complicated! I did spend half a day trying to implement a very simplified aerodynamics model, but it didn’t offer me the amount of control that I wanted. In particular, it kept either adding energy to the system exponentially, resulting in infinite speeds and crashes, or dissipating energy too quickly, resulting in a dragon slowly falling straight down as through syrup.
So instead, I decided to just fake it. Flapping your wings simply takes some vector between the velocity vector and the vertical, and applies acceleration in that direction. Pitching is even simpler: it just rotates your velocity vector. The stronger you pitch, the faster it rotates. This doesn’t add or remove any energy, so it’s quite robust. But since flapping does add energy, I had to add some drag to prevent breaking the sound barrier.
The keen reader might have noticed a problem: when a touch goes down, how do we know whether it will be a tap, or a drag? Therefore, how do we know whether to flap the wings or not? The answer is: we don’t; we’ll have to wait until the tap is released again. But because that makes the entire thing feel very laggy and unresponsive, we use a trick: as soon as a tap is detected, the wings start coming down towards the horizontal, as if we were to flap. If the tap is released before they reach a certain point, that motion continues downwards and the flapping is completed. But if the tap is held down, the motion stops at 30 degrees from the horizontal, which is the spread-winged position used when gliding. Physically nothing happens, but the graphical effect of the wings moving is enough to give a feeling of responsiveness.
And there you have it: a flappy, swoopy, soary, glidy dragon!
It took me an entire blog post to explain, but I’m planning to add some animated infographics to the game so that it’ll be totally clear from the start.