Softbody Motion in the Multicellular

After watching this video I’ve been thinking about how to smoothly move from cell based movement (flagella and cilia etc) to muscle and skeleton based movement. Basically I’ve got as far as planning an algorithm but can’t make a prototype right now as I literally code 40 hours a week now and can’t face doing any more this weekend. Hopefully I’ll get round to it soon. I thought I would post the algorithm incase anyone else is interested in making it themselves.

So basically you put a load of cells in a plane (this would be the multicellular editor) and then some of them become muscle cells, some of them are normal, and some of them are bone.

Each cell is connected to it’s neighbours. Each cell specifies the length it wants that connection to be. If the length is longer or shorter than this the cell puts a force on itself and on the cell it is connected to (equal and opposite) to try and get the connection to be the right length.

So for example two cells are 20 units apart, they both want to be 10 units apart so they pull towards each other until they are 10 units apart.

The force is determined by a function like a*|current length - desired length|^2 where a is a parameter. So this means two difference cells could desire different distances for the connection and the connections would sit somewhere in between these distances. The parameter “a” is determined by the types of cell. So if a bone cell is connected to a bone cell then “a” is very large (meaning that the cells will try very hard to stay the right distance apart). If a bone cell is connected to another type of cell the parameter “a” is smaller and if it’s two non-bone cells then “a” is small (meaning these areas are flexible).

A muscle cell changes it’s desired connection lengths over time like bsin(xt) + c where b is the size of the expansion and contraction, c is the resting length and x is the period. This means it can pulse which will move it’s neighbours closer and further away which will mean the cell will wiggle.

Putting symmetry on the cell and having the left side be out of phase with the right side will get a swimming motion.

You can then calculate the speed of the cell by working out the net motion after one complete cycle, which is something I can talk about in more detail later.

Anyway then you can add more and more bone and muscle until you have a larger creature and we can move to a fully skeletal creature editor. I think this is a nice approach as it’s smooth.

I emailed the guy who made that video and he responded and says he might open source his code soon so that might be really helpful.

2 Likes

I don’t have time to right a full response now, but check out this paper:

2 Likes

This video shows something similar to what you describe, and it’s open source, so it may be useful.
This one is the same on 3D.

1 Like

Yeah that guys stuff is pretty cool. Similar idea.

So I’ve had a bit of time to work on a prototype for this stuff. I’ve been using this paper and following it closely. Big props to Michał Joachimczak.

This is as far as I’ve got. Code in the prototypes repo.

The algorithm is basically make a Gabriel diagram of the points (which is a subset of a Delaunay triangulation) which I have done. You can place the points (cells) wherever you like and the algorithm will connect them and compute which cells are exterior (blue) or interior (red). It can also compute the interior chambers of the creature (which are pressurised to give something to push off) and compute their volume. The code is pretty terrible even by my standards, but it does work.

However I’m a bit stuck on the physics of it. The paper says they use bullet and I think it might be easier to use an actual physics engine rather than have me try to implement one. If anyone is interested in working on it with me that would be great.

In general I’m thinking (based on the discussions we’ve had so far) the overall process could be something like this.

First you play the multicellular and you get a summoning agent (which causes some other members of your species to flock around with you).

Second you get a bonding agent which causes some of these cells to snap together (maybe 3?)

Third you then play as a multicellular organism but which is still mostly pushed around by flagella and cilia, you can set some jiggling motion up but it won’t help you so much.

Fourth, over time you add more and more cells to the network and their motion becomes more important for your locomotion, the flagella and cillia start to become ineffective.

Fifth you can start to specialise the cells. If you want to make a connection between two cells more rigid than a certain threshold you have to start giving them bone like adaptations. If you want to make the pulsation a cell does more powerful than a certain (low) threshold you have to start giving it muscle like adaptations. Moreover you can adapt other cells for other functions (digestion, reproduction etc but that is rather a separate issue).

Sixth you start to use tissues rather than individual cells and at some point the view goes 3d and you’re in a different editor.

There’s quite a deep question about how ai softbody creatures evolve. Are we going to actually evolve them? (I.e. something along the lines of make 5 adaptations of each creature and then test them and then keep the best one?) Or is there some shortcut to work out what shapes would be good?

All input welcome.

Hey @tjwhale. I’m happy with my movement prototype now (hopefully somebody higher up than me will play with it and make some decisions about the values of the relevant constants) and think this will be the next thing that I look at.

Just so i’m on the right page, what exactly is happening here? If I’m understanding the intent then the circles are basically the centers of cells and the lines that connect them are “springs”. The resting lengths of these springs are then altered representing cellular expansion / contraction and how they effect the adjacent cells.

Am I on the right page?

Edit: I downloaded the paper you referenced and think I’m following now.

For this to work someone will need to write custom joint code. Here’s an example how the 2d joint / constraint works: http://newtondynamics.com/wiki/index.php5?title=CJ_2D_Joint_planar_rotation

@andross Yeah you have it correct. Basically I’ve just been trying to implement the paper. So far I’ve got the Gabriel diagram from the placement of the cells (see fig 3), that all happens in the Class creature init function starting at 152. So I think that is working fine.

Then there is the physics / dynamics. As you can see in line 413 the outer edges don’t have forces from the fluid, so that’s obv not working. Also I am not sure that the chamber pressure, from line 396, is working properly. Basically it’s section 4 of the paper that I had got to. I would love to get it working as his examples of the cells swimming around were really cool :slight_smile:

I didn’t worry about the development process yet of letting the creature grow and add cells etc (paper section 2.2) as I figured getting the creatures moving properly first was more important. Also we would need to talk as a team about how to handle a development process.

@hhyyrylainen Can you explain a bit more about that? Is that if we want joints that are constrained to only turn between certain angles? I am not sure we would need that for this prototype, the shape of the cell is maintained by hydrostatic pressure in the chambers. Do we need to custom joint code for other things / another reason I’ve not understood?

From what I’ve been gathering from the list of available things in newton: http://newtondynamics.com/wiki/index.php5?title=Newton_SDK_API_reference there’s two ways to do this. One is by creating a deformable softbody (which I’m not sure how much the movement of the points in it can be customized) and the other is creating a custom joint type that is used to link individual physics bodies (the built in joints are quite limited: http://newtondynamics.com/wiki/index.php5?title=Category:Joint_functions).

1 Like

Something i learned when working on my godot prototype is that controlling a body with a joint is really dificult and unintuitive, so i don’t recomend using them.

Would it be an option to directly do the physics directly ourselves? So we need collision between different cells, which will probably have to be handled by the physics engine. The prototype currently outputs a list of exterior cells and exterior edges which might be enough.

The the springs + pressurized chambers + drag on the water is spelled out in the paper so we could just make our own version of that which works out how the cell moves and how fast it goes.

The more I think about this the more I think “That’s really cool, but where’s the gameplay”

How do we intend to implement this sort of thing in game? It seems like a lot to ask players to decide how and when to expand / contract each cell.

That’s, imo, the best question to ask about everything.

So I think how I’d imagined it is that when you are “swimming around” the simulation is all in the background. Just like the microbe stage you use WASD and you just move at some speed based on the layout of the cell.

As for how the editor would work that is a good question. This is quite a cool video by Michał Joachimczak showing how he uses this sort of thing, basically he evolves good creatures by making mutations and selecting the best. It’s interesting though that at 2:50 he shows how his system can auto-compute a good pattern of motion for a given creature.

Because I agree that expecting the player to optimize the firing of every node would be too hard. I also think that just having a basic animation that plays regardless of how you’ve designed your cell is a bit too simple (though could be a good place to start).

If we could strike a middle ground where the player can draw out the creature with relatively simple tools and then the game could work out a good motion pattern for it I think that would be pretty mind-blowing. Especially if the pattern you drew affected how fast your creature could move. For example in his experiments the creatures evolve fish-like shapes to be good in water.

I think one shortcut we could use is that a symmetrical wave-like activation pattern will often be optimal. Basically contract the left side while expanding the right and visa versa. I’m not sure what the best way of working out the best pattern would be (he uses a neural network approach) but if we could do something reasonable I think it would be cool. Pretty much all of these are wavelike pattens of one kind or another.

So basically a balance between simple and computationally light vs being able to design any creature and test how fast they are. What do you think?

I wonder if we can get in touch with Michał Joachimczak and see about how long it took to get to a decently optimized swimming method for the user drawn animals. If it’s a relatively quick process then I’d love to use neural networking to quasi-optimize movement after leaving the editor. This would determine the animation and speed. However, if it winds up too computationally expensive then the player would face a long load screen after exiting the editor. I’m not sure how we could handle all of the different possible “animal” shapes without some sort of machine learning approach.

1 Like

I messaged him before and he responded so I think he is contactable.

I had a little play around with it and I think that, if the creature is facing up, then either a horizontal sweep or a vertical sweep will almost always be the right pattern.

So basically sweep a line across the screen and when it touches a cell it starts it’s contraction cycle. A horizontal sweep gives fish like swimming and a top to bottom sweep gives a sort of flapping.

I think this might be a reasonable algorithm to start out with and see how good it is. It would give us a good benchmark for thinking about how to go further.

Check out my new commit. The file “soft.py” has all of the physics working but I can’t get the chambers to merge correctly when converting from a Delauney Triangulization to a Gabriel Graph. Naturally the cells are still just wiggling at random and there needs to be some balancing of the numerous constants but all of the physics is legitimate (up to the time quantization, quadratic representation of fluid drag, and linear spring damping).

1 Like

That is seriously cool, good job.

For anyone who is interested here is a video of what the creatures look like. I think they look really kind of “squishy” which I imagine comes from the fluid pressure. The Gabriel diagram should allow for more limbs / fins which will help with the swimming I think.

I think this could really work well, it would be a perfectly smooth transition between singlecell and multcell, I mean you could have 2, 3, 4 etc cells connected and it would work fine.

1 Like

I don’t have any video capture software so I can’t post a video but I fixed the stuff I mentioned in my last post so that the shape is now a true Gabriel Graph so we don’t get those long skinny triangles anymore. Hopefully this is a step towards movement in the multicellular phase. The physics is there we just need to work out an efficient way to determine a “wiggle pattern” that will result in quasi-optimal swimming. I think an artificial evolution approach, as fun as it would be to watch, would prove to take too long.

1 Like

That is great.

So I added a horizonatl symmetry in the cell placement and also did a vertical sweep for offset and this is what they look like. I was really charmed by the first one, looks like a tardigrade or a bear or something.

ps if you are on windows then there is a built in video capture, just press win + g to open the xbox game bar and it has a record button

3 Likes