0
\$\begingroup\$

The horizontally placed Box2D spring is made of distantJoint connected bars, and can bend up and down just like airplane wing does when you flight (bigger amplitude thou).

Ok, the physics part works, but how do I pull on a sprite/texture to have a smooth curve when it bends and waves in box2D?

Even if I compose the picture out of small bars, and spring bends 90 degrees down, there are whitespaces on the top of the spring where it is unclamped and messed up down part where it is compressed. I wasn't able to beat this even for solid color tentacle, but what if there should be a nice picture of an octopus tentacle?

Can you please give a hint how the outer skin e.g. in this game implemented https://youtu.be/nakjRosCeH8?t=10 ? It is waving smooth curve, just like I need. Thanks.

\$\endgroup\$
1
\$\begingroup\$

I am the developer of Tricone Lab which you linked above.

I guess the first thing to say about the Tricone Lab topology layout implementation (i.e. dynamically adjusting curves) is that it does not use any off-the-shelf physics engine like Box2D. It uses a very specialized library which I wrote myself for dynamically updating 2D planar graphs.

My library uses a data structure which maintains topological relationships. So we have a set of regions, edges and nodes, but we also always know which regions border which edges, etc.

Each edge is made up of a list of vertices but this list can grow or shrink. Each region has a target size (i.e. area). If a region is below target size, then a "force" is applied to the normals of the vertices of the edges bounding the region. Forces are also applied to smooth out edges, to prevent nodes and edges getting to close to each other, and to prevent anything getting too close to the edge of the play area. The combination of different forces on each vertex is summed at each timestep and the vertex is moved according to the balance of forces. An edge acquires a vertex between a pair of its existing vertices which are too far apart (above some threshold). Similarly a vertex is deleted if it is too close to its neighbour.

So that's more or less how the "physics" works. It's probably not something which you would want to apply in another game, unless that game is also about 2D planar graphs.

However something that you might be able to take into your game is the idea that a curved edge has a variable number of vertices which adjusts according to the conditions, so that vertices are added and deleted dynamically to maintain smoothness.

Josh S.

\$\endgroup\$
1
  • \$\begingroup\$ Hi! Thank you for the answer! But, can I ask how do you render these curved lines? I have also list of vertices (obtained from box2d), but I wonder how to make a smooth line out of it (maybe even line with some suction cups which octopus have)? If I just repeatably draw a texture using this coordinate list, then it looks weird after spring is bent, since textures are squares after all and it is hard to draw smooth curve using squares (well, pixels are squares but it LOTS of them and they are tiny). Regards! //E \$\endgroup\$
    – Eugene S
    Jan 11 '18 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.