5
\$\begingroup\$

For fun I am trying to replicate the mechanics from The Floor is Jelly. So far I have successfully created "jelly islands/blocks" which are represented by an array of points and then drawn by using quadratic curves between the points. I am also able to get the jelly effect by having each point hold a velocity value as well as a relationship with its neighboring points to allow the springyness effect.

The above works well and gives a good representation of how the actual game seems to do it.

The part that I am kind of stuck on is how to resolve collisions with the character. I can successfully detect when my character (currently just a square represented by 4 points) comes into contact with the jelly island. However, I cannot think of an efficient way to make it "stick" to the ground and then smoothly interpolate along the curve once a force is applied to the jelly that causes it to move. Also, I want the character to stick to the ground unless the user "jumps" which means that the character should follow the ground through it's wobbles rather than go up into the air.

I could pass the character controller the array of points representing the island that it is currently colliding with, but then iterating through all of the points and finding the points closest to the character seems like a lot of work to do on each frame. In addition I am still not sure how I would get the correct position of the character along the curved ground (particularly when it is wobbling).

Any suggestions are appreciated

Update

Clarification as I fear that I wasn't clear enough above. What I mean when I say that I can successfully detect when my character comes into contact with the jelly island is that I am currently using the Point in Polygon algorithm to detect when the jelly island is not moving/wobbling this breaks of course once the jelly island has a force applied to it.

To fix this I have been looking into breaking the island into many line segments along the curves (how collisions with quadratic/bezier curves are usually handled), but I'm afraid that this will be too much work to do on each frame. In addition I am still stuck on the problems described above.

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

I could pass the character controller the array of points representing the island that it is currently colliding with, but then iterating through all of the points and finding the points closest to the character seems like a lot of work to do on each frame

When the collision first occurs you could save the id/index of the point in the array that is closest to the player. Then while the player is closest to this "center" point, you can just iterate over that point and the center point's neighboring points instead of all the points in the array. If the player moves away from the center point and is closer to one of its neighbor points, you can set that neighbor point as the new center point. If this works without glitching too much, then instead of iterating through each point in the array every frame, you'll instead just have to do a few distance checks every frame.

In addition I am still not sure how I would get the correct position of the character along the curved ground (particularly when it is wobbling).

My guess would be that you need to store the x position of the character along normal straight ground and use that position to calculate what position of the curved ground that the character lines up with and should be at.

\$\endgroup\$
  • \$\begingroup\$ The first part of your answer sounds like a good suggestion. After contact with the ground I would only need to check 2 points, the ones on either side of this "center" point. However, for the 2nd part, what if the player jumps off of resting ground causing a wobble and then moves slightly while in the air (but still between the same 2 points as before). The ground is now wobbling and I'm not sure how I could use that x coordinate to really do anything. \$\endgroup\$ – Kinru Nov 23 '14 at 6:12
  • 1
    \$\begingroup\$ I'm not sure If I understand what you mean. If the player has jumped into the air, he would no longer need to be aligned with the ground until he landed, right? Perhaps while the player is airborne, every frame you could check his current x and y position to check for a collision with the points/lines of the land the player is closest to. Then when a collision occurs, you can re-align the player to the land. \$\endgroup\$ – Gigggas Nov 24 '14 at 6:30
  • \$\begingroup\$ Ok I see what you mean and that resolves the x coordinate for me, but I'm not really sure how to resolve the y coordinate in terms of the math. Is my only option to find the closest 2 points to the character and then break the curve up into n line segments, followed by iterating over the line segments and finding where the character will actually collide? In addition, I'm still unsure of how I could "stick" the character to the curve while the curve is moving. \$\endgroup\$ – Kinru Nov 24 '14 at 14:54
0
\$\begingroup\$

This is not something that you can cover in a question. To get proper results you need a physics engine that supports soft bodies collisions.

Use something like this.

Essentially the characters body is supposed to stick to the ground because it doesn't stop when it hits the ground. It's like a ball hitting a blanket, or a spring more precisely. So when the ball hits the ground, it looses some speed and the ground gains some speed. When the ground is pushed out of it's natural orientation it begins to apply more and more force in the opposite direction like a spring F = -kX where F is the force of the springy ground and X is the distance from the natural position of the ground segment. The last symbol, k is just about any number that you see fit. If it's small, the the ground is more stretchy and if it's large then the ground is almost rigid.

To detect collisions you don't need to break the curve into a million pieces. Very few pieces suffice to detect collisions reasonably. To speed up collision detection, place the segments and the character into a grid for fast collision detection.

Read about it here.

\$\endgroup\$

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.