Soft body physics test

2 favourites
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Soft body physics for things such as jello are always cool to mess with. Every so often I try to find ways to do it better. Typically they are done with a grid of points connected by springs. The only downside is they can collapse on themselves sometimes. But the following corrects that by having it try to keep the same area from one frame to the next. The result a very robust simulation that doesn't break.

    Here is an example using the paster addon, and one without 3rd party plugins that doesn't distort images.

    dropbox.com/s/ikcd3sxj9eowomg/jello_paster.capx

    dropbox.com/s/zj51hzstahv0f8n/jello_no3rdParty.capx

    dropbox.com/s/ray56gskqwpiwfy/jello_c3.c3p

    Edit: ported to c3 as well. It fit within 25 events.

    Cool reference:

    matthias-research.github.io/pages/tenMinutePhysics/index.html

  • Ha ha nice soft-body jiggle really satisfying to watch. Combining this jello-physics with meta balls will make things even cooler.

  • Pretty cool I can see this being used for a game like Mutant Blobs Attack or something, any way to make the "blob" thing move with WASD?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Sure, the physics is a position based dynamics simulation, so you just need to move the points.

    left is pressed

    — p: set x to self.x-100/60

    Just put that event towards the top of the event sheet. That would move it left at 100pixels per second at 60fps.

    But we can probably do better. Instead of moving all the points we could move the top ones more than the bottom ones, which would let it roll.

    Var ymin=0

    Var ymax=0

    For each p

    — set ymin to loopindex?min(ymin,p.y):p.y

    — set ymax to loopindex?max(ymax,p.y):p.y

    Left is pressed

    — p: set x to self.x-(self.y-ymax)/(ymin-ymax)*200/60

    That should move the top points more than the bottom ones. Might need to change the 200 if it doesn’t move it enough to roll.

  • Sure, the physics is a position based dynamics simulation, so you just need to move the points.

    left is pressed

    — p: set x to self.x-100/60

    Just put that event towards the top of the event sheet. That would move it left at 100pixels per second at 60fps.

    But we can probably do better. Instead of moving all the points we could move the top ones more than the bottom ones, which would let it roll.

    Var ymin=0

    Var ymax=0

    For each p

    — set ymin to loopindex?min(ymin,p.y):p.y

    — set ymax to loopindex?max(ymax,p.y):p.y

    Left is pressed

    — p: set x to self.x-(self.y-ymax)/(ymin-ymax)*200/60

    That should move the top points more than the bottom ones. Might need to change the 200 if it doesn’t move it enough to roll.

    Thanks for the swift reply, as always. But unfortunately I can't get it working properly, I assume you mean to set the condition if left key is "held" not pressed, well I did that 'cause the press condition doesn't really move the object at all, and well the result is a lot of jank, as soon as I let go of the key, the object returns to its previous location, given that it of course moves at all

    Would appreciate if you had the time to demonstrate a proper working solution, or a physics based simulation if possible. Appreciate your help.

  • Here is a test of keyboard controls. It involves two steps:

    1. find the minimum and maximum y of all the points.

    2. apply an acceleration to the points while a key is down. It uses the previous ymin,ymax to apply more acceleration to the top points than the bottom points. This causes the object to roll.

    The formula used is: 800*mdt*((self.Y-ymax)/(ymin-ymax))^10

    (self.Y-ymax)/(ymin-ymax) gives a value from 0 to 1 for each point. The top points will have a value of 1 and the bottom have a value of 0. It's changes linerarly for the points in between. I added the ^10 to give it a steeper curve. Basically with that the points at the top will still have a value of 1 but more of the points below will have a value closer to 0.

    The 800 is the force, and mdt is the timestep.

    Can be read as a force of 800 is applied to the top of the blob. The force bleeds to some of the points close to the top but most of the low points will barely have any force.

    I only did it for the plain c2 version but it should be simple enough to add the the others. Events 7-12.

    dropbox.com/s/s1m388u87wbajn0/jello_no3rdParty_keyboard.capx

  • Here is a test of keyboard controls. It involves two steps:

    1. find the minimum and maximum y of all the points.

    2. apply an acceleration to the points while a key is down. It uses the previous ymin,ymax to apply more acceleration to the top points than the bottom points. This causes the object to roll.

    The formula used is: 800*mdt*((self.Y-ymax)/(ymin-ymax))^10

    (self.Y-ymax)/(ymin-ymax) gives a value from 0 to 1 for each point. The top points will have a value of 1 and the bottom have a value of 0. It's changes linerarly for the points in between. I added the ^10 to give it a steeper curve. Basically with that the points at the top will still have a value of 1 but more of the points below will have a value closer to 0.

    The 800 is the force, and mdt is the timestep.

    Can be read as a force of 800 is applied to the top of the blob. The force bleeds to some of the points close to the top but most of the low points will barely have any force.

    I only did it for the plain c2 version but it should be simple enough to add the the others. Events 7-12.

    https://www.dropbox.com/s/82wzrtp796gjbnj/twoInstances_sameTypeOrFamily.capx?dl=1

    Thanks for the assistance, but I think the link is for the wrong file. Anyway I will try this as soon as I have the chance!

  • Link now fixed. Guess I need to verify the links I’m copying from Dropbox. That’s been happening a lot lately.

  • Link now fixed. Guess I need to verify the links I’m copying from Dropbox. That’s been happening a lot lately.

    Thank you for the kind help, it works great for the intended effect :)

    I'm now trying to make a jump mechanic while the object is touching the floor, and also make the object rounded or blob-like.

  • One idea for the jumping would be to relax the spring forces momentarily then make the spring forces stiffer for a bit. But I guess there may be other ideas.

    Making other shapes should be possible, but it just would take more setup. All the rest lengths of the edges, and all the rest areas of the triangles. The other issue is while a grid is easy to texture with distort meshes, other shapes could be trickier.

  • One idea for the jumping would be to relax the spring forces momentarily then make the spring forces stiffer for a bit. But I guess there may be other ideas.

    Making other shapes should be possible, but it just would take more setup. All the rest lengths of the edges, and all the rest areas of the triangles. The other issue is while a grid is easy to texture with distort meshes, other shapes could be trickier.

    I was able to achieve this by just applying some force upwards when releasing the down key but the issue here is that the object jumps too when in air, not sure yet how to lock it down to only jump when it's on the floor.

    Here's the edited capx: dropbox.com/s/a1qj29x8ix2k17t/jello_paster%20%28edited%29.capx

  • Finally got around to finding a decent solution to this.

    To do the jump I have it squish horizontally as if it was a muscle. I works pretty well as it jumps only if on the ground.

    dropbox.com/s/5ao27efbsdox8bm/jello_no3rdParty_keyboard2.capx

  • Finally got around to finding a decent solution to this.

    To do the jump I have it squish horizontally as if it was a muscle. I works pretty well as it jumps only if on the ground.

    https://www.dropbox.com/s/5ao27efbsdox8bm/jello_no3rdParty_keyboard2.capx?dl=1

    Sorry, I haven't been active on the forums for the last couple of weeks couldn't reply in time.

    This works perfectly for the intention, thank you a lot I appreciate the time and effort you put into helping out.

  • All in all very cool! Unfortunately, it uses quite a lot of performance. Would be cool to see something like this integrated in the official physics plugin which would probably result in better performance (with java script)

  • Events provide the most flexibility. JavaScript would be faster but is more quirky integrating with other construct features.

    Personally I have no interest in making plugins and the maintenance they require. Also they are inherently more limited by what features are provided.

    On face value it would make sense to tie this to the physics behavior but in practice it would be better to make something completely independent.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)