Refactoring Movement—Flagella, Cilia, and Pseudopods

Refactoring movement is one of the other things I would like changed for the 0.3.3 release. Currently, we only have one movement organelle, flagella, whose speed is only limited by your ATP store, which isn’t very realistic. Adding 10-20 flagella to your cell allows you to be flash—moving faster than the game can process, resulting in a crash—and doubling your flagella amount doubles your speed. There should be a logarithmic (if not hyperbolic) taper, which can be solved by factoring in drag.

The basic, simplified formula for drag that we will use is R = ½ρCAv². ρ is the density (which in our case will be a random constant that we will chose to make the simulation look good), C is drag coefficient (which is basically the shape of the front half of the object, more on finding this later), A is the cross-sectional area (which is the longest line of hexes perpendicular to the microbe direction), and v is the velocity of the object. The velocity is a number that we will be getting from the physics engine, which uses F = ma and vₒ = vf + a∆t (where the mass is the number of hexes and the force is number of flagella multiplied by a constant).

We know everything except for C, which can be found using this nifty table:

After you exit the editor, an algorithm will attempt to figure out to which of the above shapes the cell is closer to, and will approximate the drift coefficient.

To move the microbe we will just do this:

v = 0 // last frame velocity
Every frame do
    Find R // The drag force using the predefined constants ρ, C, and A, and the last fram velocity
    Find F // Add all of the forces generated by flagella (constant flagella force multiplied by cosθ)
    Find I = (F - R)*dt // The impulse
    v = physicsComponent.getVelocity() // Get the new velocity

I am kind of tired now, so I’ll get to cilia later, but in short, cilia have a much smaller thrust force, but a larger torque. This torque will be affected not by pressure drag as above, but by frictional drag (which depends on the cell outline). This means that circular and smaller cells turn faster, and larger and weirdly shaped cells turn slower.

To be continued…


The above half talked about thrust. This second part will describe rotating your cell. Both flagella and cilia have a thrust component, with the former have a greater thrust and the latter a greater torque. Pseudopods will be somewhere in between, e.g.:

                      Thrust               Torque
Flagella                10                   2
Cilia                   3                    10
Pseudopods              6                    4

For fricitonal drag, we will use a slightly less scientific formula. The frictional drag is basically equal to the surface area multiplied by a number (since sluid density, surface material, and velocity are assumed to be constant). We will assume cells are two dimensional and will just use the perimeter instead of surface area (which can easily be found by calculating the number of hex edges on the outside of the cell). We will then multiply this by the “unevenness” of the membrane (which is the perimeter sqaure devided by internal area, or total number of hexes). I am thinking of letting players create star-shaped cells for the next microbes (since a lot of people have been asking for them, and they are realistic by using microtubules), they will just be detrimental because rotating will be much harder.

To reiterate, this is going to be our semi-realistic calculation of frictional drag that will be used as a factor to decrease the torque:

Torque calculated from movement organelles * Area / (perimeter ^ 3) * random constant

And that concludes our brief science lesson. Yay for physically accurate movement and new organelles!


Huh, I hadn’t thought about this before. It sounds great though, and would really help to create an intuitive movement system (as well as adding another consideration for the player when building a microbe). Are you also planning to wire the fluid simulation into microbe movement for the next release, or is that off-topic here?

The only place where I disagree with you is in the strength of drag – due to scale effects, microbes swim through water more like we would swim through, say, honey. So, there is effectively no momentum (which is something that’s always been contentious for us, cuz having some momentum and drift might make swimming feel more fun), and flagella and cilia work more to push the microbe forward (as a person would, say, shove a box forward along the ground) rather than apply acceleration (as if they were pushing a ball instead).

For cilia and separate torque vs thrust components, I actually tried a hackish solution once a long time ago, but when I realized we’d need to refactor just about the entire movement dynamics code I decided to abandon it.

For example, one complication is that cilia still apply a thrust tangential to the microbe surface, but due to it being so difficult to displace water, then the torque component is the only one to act, causing the microbe to spin in place; unless you have cilia on the other side applying a countering torque, in which case the microbe can swim.

We had a guy, @lowreynolds4life, who knows a lot about this stuff, so if he’s available then that would be great.

Depends if I have time or not.

Don’t know what makes you think I disagree. I never said that the density will be one; I even wrote that it “will be a random constant that we will chose to make the simulation look good”. At the microbial size, the fluid is really dense, which we will solve by setting a very high frictional coefficient. This will probably be more fine-tuned once once most of the other features for 0.3.3 are in.

Assuming that cilia can move in only one direction, we will probably give the cilia (and flagella) 2 parameters—thrust and torque. The torque will only be used when rotating your cell (as it would be unintuitive to turn your cell when you press the ‘W’ key, especially since we always have the microbe face the cursor). The thrust force will be very small compared to the flagella, but it will still be there.

Anyway, I’m going to update the first post with cilia stuff, so read it after this message.

Isn’t cilia faster than pseudopods so wouldn’t it have a higher thrust?

It’s not a matter of density, but viscosity. These drag equations and physical assumptions don’t work at low Reynolds numbers. A better starting point would be something like this.

Okay, you’re right. I do disagree. Doing what you suggest is way too complicated in my opinion, and would have a virtually indistinguishable result from using R = ½ρCAv² for drag and the sum of the flagella forces for thrust. What we want is to make sure that the player cell is not infinitely fast, and that having 10 flagella does not necessarily make you twice as fast as if you had 5 flagella. The system I described does exactly this. But for the sake of argument, let’s assume we are in high viscosity (low Reynold’s number).

We have the equation for Stokes’ drag as R = b * v, where b is a constant that depends on the shape of the object and v is the velocity. In other words, b is linearly related to A from before (the cross-sectional area), and C (the drag coefficient). C is related to shape; however, in high viscosity, this number will be different, but not by much. Either way, we will be using an approximation, and both in Newtonian drag and Stokes’ drag a cube will have a larger drag coefficient than that of a circle, which is larger than that of a streamlined body.

Finally, we have that in high viscosity, drag is linearly (as opposed to quadratically) related to velocity, which is opposite of what we want—each new flagella should add significantly less speed than the previous one.

There’s the matter of fluid friction (which doesn’t scale with speed), but as I mentioned earlier, we can just set this value higher to simulated a viscous fluid.

So even if we do switch, which I don’t think we should, the resulting equations are close enough to not make a big difference—we don’t need physically accurate results (we’re building a game not a rocket) and we are already doing a lot of approximation; plus, velocity isn’t high enough for v to be much smaller than v².

(Tagging @tjwhale to check my reasoning/physics)

IMO there’s three constraints.

  1. The realistic physics of swimming microorganisms.

  2. The computational requirements of letting people go too fast.

  3. Fun and game balance.

I think on point 1 moopli is right that linear drag is more realistic. The arguments for non-linear drag come from points 2 and 3.

Personally I think fun is the most important thing. Swimming around has to feel good by itself so I think game design / fun should be much more important than realism. Just because if it feels sludgy or boring to swim around then the game isn’t going to be fun.

I also agree that it would feel lame to have a limit in the editor like “you’re not allowed to put more than 5 flagella on because you’ll be too fast for your computer to handle it, sorry”. It would feel better to have a soft wall where they get less effective the more of them you have. But this is an argument from point 2 not 1.

1 Like

Luckily, while drag would be linear, there is still a top speed since no flagellum or cilium can make the microbe move faster than it can make water move past it.

What that means is that microbe speed as a function of flagella, cilia, shape, etc; is actually convergent. So rather than a quadratic discounting that still allows a limitless top speed, there should actually be an exponential discounting.

Oh and I must have misrepresented what I meant entirely, because to me this was never about doing any sort of realistic simulation, but about checking our assumptions and thus using equations that approximate reality.

I’m still confused by what you are trying to say. At some point the microbe will reach terminal velocity because the drag will equal the thrust force in both cases. This just happens slightly faster in Newtonian drag (although not by much since our speeds aren’t that high). Could you post a function/equation as to what you mean?

It’s alright, I think I just haven’t been explaining my points at all well.

Fish and boats propel themselves by imparting momentum to the water that they push against, which by newton’s third causes them to move. Microbes, on the other hand, swimming under low-reynolds circumstances, must instead propel themselves through cyclic deformations (in particular, deformations which satisfy the scallop theorem, outlined in the paper I linked).

These types of deformations cause motion that scales linearly with the rate at which the motion is carried out – so, for example, no amount of flagella can push a microbe faster than a single flagellum can move on its own. I guess it’s analogous to the hard limit imposed by the speed of sound in water.

Since we effectively have a top speed bounded by the speed of a lone flagellum, then what we should do is take a weighted average of the top speed of each propulsive element on the microbe, with a term to represent the strength of the drag forces on the microbe body. Since drag scales with velocity, and since propulsion by deformation is essentially done by turning drag into a propulsive force, then we can just average all drags to get the microbe’s top speed.

v_max = weighted_arith_mean(each (weight, velocity) in wv_pairs)

The other point I was making was that I don’t think that the thrust of cilia is as simple as you suggested. Since cilia produce tangential thrust, you could sum the forward components of all tangential thrusts on the left side of the organism, and same for the right side, and the total ciliar thrust would be double the smaller value.

We can’t simply assume that cilia have a tiny thrust (unless we’re willing to ignore science for the sake of gameplay) because ciliated protozoans are actually the fastest swimmers, thanks to them effectively lacking any friction drag (because of course, the friction drag that would ostensibly be caused due to the body moving through the water is actually used by the cilia covering the body to provide thrust). But I don’t intend to die on this hill; as I agree that it’s better for gameplay to differentiate cilia and flagella more.

I still have no idea what you are talking about with flagella, unfortunately, but if you’re saying that 2 flagella should be as fast as 1, then I disagree no matter how realistic that is. Otherwise, if you’re saying that microbes don’t experience Newtonian (or Stokes’) drag pushing them in the opposite direction of movement or that they do experience drag opposite of their direction of movement (R = -b * v), but the forward thrust generated by flagella is different (so you wouldn’t add them all up as we do now), then I’m fine with that as long as it looks nice from a gameplay perspective.

That’s a great idea.

I’m not sure I totally understand either. I get the whole “can’t go faster than the flagella” thing.

A boat on a lake can go faster than it’s oars because after they finish a stroke it has some momentum that carries over to the next stroke. But a boat on a sandpit can’t go faster than it’s oars because it only moves when the oars move and when they finish the stroke it immediately comes to a halt.

1 Like

But if you add multiple people, each with a pair of oars, shouldn’t you be able to go faster than one person with oars, since the total force is greater and thus the impulse/accelaration?

1 Like

Luckily I’m not – tjwhale’s analogy is a good one, multiple rowers with oars will move the boat faster on sand, but even an infinite number of weightless rowers won’t be able to move the boat any faster (on sand) than a weightless boatless rower.

Here’s another way to think about it: at top speed, the drag forces pushing it forwards will match the drag forces resisting movement. The resistive drag force is proportional to the velocity, so at top speed, the velocity is proportional to the total propulsive drag. And again, since those drags are proportional to velocity, you can just use the top speed of every propulsive element, with a weighting coefficient to represent how ‘draggy’ it is; and so you get a weighted average of a bunch of speeds, where one speed is 0 and represents the resistance of the microbe body, weighted by how draggy it is, and the other speeds are the top speeds of all the propulsive elements, weighted by how ‘draggy’ (really, how powerful) they are, and the result is the speed where drags balance, ie, the top speed.

And so, we wouldn’t be dealing with impulses, accelerations, or dt in this calculation, but can just set the velocity of the microbe using the top speed (or a fraction thereof, for engulfing, for example).

And of course, all of those speeds would be taken as the velocity component in the direction of motion.

1 Like

After giving this yet another attempt, I think I have finally come up with a solution for flagella movement that will satisfy both me and moopli. The equations below are based on a paper on resistive force theory by Gray and Hancock and apply to very low Reynolds numbers 10e-4 to 10e-2 as well as a Eukaryotic flagellum that goes left to right instead of a spiral motion (don’t remember who first pointed out this distinction, but kudos to you).

Okay, so after spending 30 minutes trying to write this out I gave up. Here is a lecture pdf talking about flagella force movement. It makes perfect sense as is derives one equation from the previous and the proof seams solid, but my high school level physics classes aren’t enough to paraphrase what is going on. You can read the tl;dr of the lecture below (if your physics sucks as much as mine) or actually follow the link and help me not make a fool of myself posting this.

The force generated by a flagellum is:
F = KₜL*[(V − U)β − V ] + KₙL*(V − U)(1 − β). (equation 3.18)

Kₜ is the tangential resistance coefficient (equation 3.6)
Kₙ is the normal resistance coefficient (equation 3.8)
L is the length of the flagella
U is the current speed of the microbe
V is the wave speed
β is the mean square cosine of the body shape, whatever that means (equation 3.17)

The drag force is:
D = KₙLUδ (equation 3.19.5)
No idea why the length of the flagella is in this equation, and I’m not even sure I’m looking at the right equations.

Anyway, I’m pretty sure I’m in over my head with this physics stuff. I’ll try to find some other papers on the topic, but hopefully this helps someone.

I think this is all too complicated for the result we want (press a button and the microbe moves).

This is what I think you, @Moopli, were getting at.

Each propulsive organelle gives you some amount of force, like flagella 6, cillia 3 etc and then you divide this by the mass of the cell to get the speed.

So if I have 2 flagella that gives me 12 force and if I have 20 organelles my speed is 12/20.

Then when you press the button you get this speed instantly and when you release the button you stop instantly, basically there is no acceleration. Have I understood remotely correctly?

Basically the distinction is this: do you smoothly accelerate to a top speed when you press the button and then, when you release it glide to a halt. Or do you go immediately to top speed and immediately stop. That’s the only distinction the player will be able to experience.

Yeah, that’s the gist of it. I suggested a weighted average instead of a straight average, but it boils down to the same thing. As for dynamics, I agree with a bit of smooth acceleration rather than instantaneous motion. Microbes zip around very fast compared to their size, so we’re effectively slowing down their motion already to make for a playable experience, so we aren’t exactly gonna lose on realism by making acceleration non-instantaneous (moreover even if it weren’t justifiably realistic, I think it’s necessary for the game). Imo, you should reach top speed I a bit over half a second, and coast to a stop in less than that. I also think it’s worthwhile to make different propellers have different acceleration characteristics, it can help differentiate them, and might feel nicer. Cilia could have a more twitchy response, for example.

In some pms with @TheCreator, I suggested a smooth drag curve that isn’t perfectly linear, to allow us to use a constant thrust to get the microbe up to top speed (and at top speed drag would match thrust, of course, and then climb slightly faster). We’d just use my formula to find the top speed, feed that to the drag function, and the drag function would spit out drag for current velocity.

1 Like

@Moopli, but how is that different from what I originally suggested? Each flagella provides a force which bullet divides by masd to get the acceleration, then we plug the current microbe velocity into a drag formula, so eventually the microbe reaches top speed. It’s going to be quite easy to tweek this to make the microbe reaches top speed fairly quickly and the decelerate to a stop even faster.

Wouldn’t it make sense that some shapes would be better since they would allow for more fine movement/stopping? Not neccesarily top speed but better for stopping and turning. Also doesn’t having more stream lined bodies mean it takes a longer time for them to stop? So it’s sort of like a balance?