Let's fly into space! – a DD1354 project blog

It's done!

Since the last post, I've implemented lift and wind, and I've also tweaked the various parameters of the simulation (aerodynamic coefficients, engine thrust, etc.) for better realism. And now the implementation is finished! Here's a demo video that shows pretty much everything:

Note: This blog has been archived to my KTH site. .space domain renewals are expensive ;)

View from space

It doesn’t look amazing, but this is actually a full-scale Earth. And an updated HUD. Large-scale simulations like this require some tinkering, as Unity transforms are based on single-precision floats which aren’t very accurate. In my case I’ve used a popular floating origin script to achieve this result, and in most computations I work with doubles that get rounded down when neccessary.

Environment image

Implementing drag

Drag is almost fully implemented now. It turned out that simulating it in a semi-realistic way isn’t as terribly difficult as I thought, although it’s somewhat convoluted; the drag force is proportional to the reference area multiplied by the dynamic pressure, which in turn is equal to the air density (which isn’t too hard to calculate based on atmosphere model data using the barometric formula) multiplied by the vehicle velocity squared, divided by two. And that’s mostly how I calculate the drag force in my simulation – I simply multiply the reference area and the dynamic pressure with a static drag coefficient.

The only things remaining there are an approximation of the center of pressure, where the drag force acts (it’s also where the lift force acts), and calibrating the drag coefficient so that the strength of the force is realistic, which I will do when I have pretty much everything implemented.

In other news, I had a pretty bad bug where the AddForceAtPosition RigidBody method, which I use to add the torque generated by gimbaling, would completely mess up the trajectory. I couldn’t figure out what was wrong despite it bothering me for several days, but after trying to use it again today… it just worked. Nice.

Update 2019-03-09: The bug seems to have been caused by the Unity-calculated center of mass being slightly off, which probably is a result of the mesh not being completely symmetric when exported from the CAD software. This is worked around by forcing the X and Z values of the center of mass to zero.

Basic UI and controls

No progress on the physics today, because I wanted to work on handling input and having a working HUD. I also wanted things to happen in response to input (it would be quite pointless to have input handling otherwise), so now we have throttling, mouse camera control, and basic gimbaling. The rocket design has been modified a little and is now closer to one of a typical real-life launch vehicle.

Basic UI image

It moves!

Well, you have to start somewhere. Here’s a very simple simulation of the rocket just flying straight up – the only forces in place are thrust and weight, and they’re only partially implemented. The stages can however run out of fuel, and as they do, the mass of the rocket decreases. I’ve also made it possible to eject the first stage and initiate the second one with a keypress.

First test video

Introduction

Welcome to this magnificent blog, where I will document the process of building an interactive simulation of a rocket launch into orbit in the Unity game engine. You can check out the project specification here.

Now, the project is called “Launching into orbit” while the blog is called “Let’s fly into space!”, which might be a bit confusing. I made it this way mainly because “Launching into orbit” is a pretty boring name; “Let’s fly into space!” sounds much better (and outer space kind of starts at 100km above sea level anyway), and makes the thing seem cooler than it really is, but it’s unfortunately not specific enough to be used as a name for the actual project.

To get things started, here’s a quick look at the two-stage rocket that I’m planning on putting in the simulation. The gimbaled engine nozzles eliminate the need of having fins for stabilization. Rocket image