Need some help calculating variable drag, based on velocity and orientation

I’ve been programming for years, but am totally new to 3D game development, so began learning by making a space game with PlayCanvas, and would be grateful for some help with the physics.

I created a little demo project that only includes the stuff that’s relevant to the issue I’m having.

The demo has a ship, which is really just a camera with a crude HUD in front of it, as well as a simple ‘space object’ (constructed from a few primitives) floating in the middle of the only scene (an otherwise empty space with a Milky Way skybox).

You can pitch and roll the ship with the cursor keys, and you can increase and decrease thrust with W (increase) and S (decrease). You can also zero the thrust with the Space key.

The thrust is displayed in the HUD (ranging from -100 to 100).

The HUD also displays the (Boolean) state of the Velocity Dampening (VD) and Rotation Dampening (RD) features, which are both disabled by default. Velocity Dampening can be toggled with V, and Rotation Dampening with R.

When dampening is disabled, the ship flies around as though it’s in a vacuum. Enabling dampening reduces the velocity and/or rotation by some percentage per second, making flight easier (but less efficient).

The problem is that I ultimately want to approximate the feeling of flight through air (superficially - this is not a physics simulator), and the dampening is currently applied uniformly (by applying mulScalar to the velocity and rotation vectors, using a value like 0.999).

I would be very grateful if anyone could explain how to dampen the velocity by different degrees, depending on how the ship is oriented relative to the direction of its velocity, effectively giving the ship very little drag along its Z-axis, with more drag along its X-axis, and more drag still along its Y-axis.

I understand that there’s more to it than that (like the ship should not glide backwards as efficiently as forwards), but if I knew how to vary the drag, I could (hopefully) manage from there.

I’d appreciate a direct explanation, but am also very interested in resources that explain this kind of video-game physics (in hacker terms), and am willing to invest the time to learn some maths.

Could anyone offer some advice, please? Thank you.

1 Like

I’ve started hacking on the demo now (and learning linear algebra) to figure it out on my own. No worries.

1 Like