141. Flying is hard!
Having imported a nice 3D aeroplane model into Codea, I thought the main problem with flying it was going to be making it realistic. Well, yes, that is a problem, but first, I find I have to master rotations.
An aeroplane is rotating in three dimensions at once, and that gets tricky mathematically and visually – by that I mean it’s hard to figure out what’s going wrong by just looking at the screen.
You see, I put a sphere around my plane, covered with a sky texture, so my plane flies inside its own little world. But because the sphere moves with the plane (it is centred on the plane, so the plane can never fly outside of it), I can’t even tell if I’m going forwards or backwards. In fact, when I put a second plane in the sky to act as a target, it took me some time to realise that the reason that target was disappearing into the distance was that my plane was actually moving backwards!
I’m tilting the iPad to control the plane, and it only has two directions, whereas the plane has three. So I’m using roll (ie tilting one wing up) to also change the yaw (the direction the plane is pointing). This is quite tricky.
The video above shows where I’ve got to. The plane does a smooth circuit around the sky and tries to hit the target plane, which is just sitting in one spot, slowly spinning. It all goes well, except that my plane stays tilted toward the end when I want the wings to be level.
I’ll post an explanation on how to do all this when I figure it out (or am rescued by a kind mathematician!).