Adding collision to rope made using verlet integration

Godot Version

4.2

Question

Hi,

So I created a rope using something called verlet integration, basically a series of points that each store location values, which result in a pretty realistic rope.

My goal is to make this rope react to its environment, right now it does not have any collision detection whatsoever.

My question is, does anyone have an idea how one would add some sort of collision detection to this type of rope?

If this is not enough info, please let me know so I can provide more.
I am not sure if I am allowed to add links but here I go:

Thanks to anyone reading this!

You could put script into a rigidbody and put a collision shape. Then to solve the collision physics you could set the collision mask to look for your normal world object collision layer and use the body enter signal to then start your custom collision solver.

Thank you so much, I will try this

Hmm, I thought about this more… I still don’t know how this specific rope math works. For my previous idea to work each point needs its own rigid body. This may be too costly or not easily feasible with how the math works.

If rope segments and points are in an array and have a position you could setup an area2d+collision shape per point. (Rigidbody may be excessive, and as I think about it more may not work very well because warping bodies, by changing their position directly, my have strange behavior when moved like that. E.g. like not detecting a new collision!)

My second option would be to cast short rays in the direction of motion for each rope point. The target length and direction being the new position for the point. If the ray collids with something, meaning the rope would pass through the wold object, you only move it to the collision point. Then your next point you calculate will have the previous point position that collided with something.

Look at the casting ray tutorial and this class for Godot.

Thank you, I am trying a raycast solution right now, it is not working yet but I will let you know.

After 8 months of gruelling labour (jk, I was doing other stuff as well) it is finally solved (with your help).

You can see the solution working here:

Bad explanation here:

When you have engaged the grapple, you want to cast a ray from the point you are shooting to the end point of your rope (let’s call it your grapple point).

If that ray gets intersected by geometry, you want to create a rope between your original grapple point and the collision position.
You also want to keep your original rope segment form the shooting position, but move the position you swing around (pivot position) to the collision point.

Now you have one active rope segment (the one you swing around) and one static rope segment (representing a rope between your original grapple position and the collision position.

If your rope has been “broken”, you also want to cast a ray from the shooting position to the START position of the previous static segment. If this ray can see that start position, it mens that you are not tangled anymore and can release the static rope segment and your active rope segment now again runs from the shooting position to the start position. You also want to again move your pivot position to this start position.

I hope that was not too hard to understand, sorry for the mumbo jumbo.
TLDR:
If you are grappling, cast a ray to see if the rope is being obstructed. If it is, split the rope into two segments, and cast another ray to see if it unobstructed again, and resolve.

It is important to node that I have decided to keep the “series of points way of displaying the rope” purely visual.
The actual rope the player will swing around is a simple bunch of rope segments with a start and end position. This made is way simpler to resolve for collisions, more consistent as well as way more performant.

Thank you so much for your help :index_pointing_at_the_viewer::grin:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.