# Grappling Hook Code

This topic is 5026 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I want to program a grappling hook, and ive got all the code figured out for the actual hook and such, but how might i program a realistic dynamic rope hanging from it? can anyone point me in a specific direction with this because i have nooo clue. thanks

##### Share on other sites
You're going to want to look into physics simulation -- numerical integration with constraints. The basic idea is to approximate the rope with a series of discrete particles, all connected to each other. Try playing with different numbers, seeing what fits a good compromise between looking good enough and being fast enough. Basically, you have these distinct points all connected to each other with simple rules called constraints that describe their connectness. The idea is that you update all the particles' positions independently in some great physics loop, and then relax all the constraints, having each particle pull on particles they're connected to. When you get the simulation working right, it'll look very good and very natural. I'm sure you can find countless articles and demos showing this basic, very broad, and very generally applicable physical simulation idea.

Keywords to search for: physics simulation, numerical integration, constraints and/or constraint relaxation. You may want to start with verlet integration, as there is an excellent article by Thomas Jakobsen on the topic (this is how people generally do ragdoll physics).

Let us know how it goes!

##### Share on other sites
I guess if you want the rope to be affected by forces you have to seperate the rope into small line segments and calculate the forces at their connections.

If you only need a realistic hanging rope and the only outer force is the gravity then every rope, power transmission line or small string follows the cosinus hyperbolicus.

-- Constantin

##### Share on other sites
It depends on what kind of rope physics you want. A Liero-style (or Bionic Commando) ninja rope (well, rubber band really) is easy while the rope in Worms is a lot more complicated.

Here's what we do to simulate the former.
Just calculate the vector between the hook point and the player's position. Scale it down by some constant and add it to the player's velocity.
playerVelocity += (playerPosition - hookPoint) * ropeForce
Don't forget to apply gravity and possibly movement forces as usual.
And that's really all there is to it.

Additionally you might also want to clip the force at some extreme value. But that's relatively easy to implement.

##### Share on other sites
cool thanks for that tip. i originally planned just to do it leiro style (for the simplicity) but i've since shifted the gameplay to more strategy, so i wanted a rope that could quietly get you anywhere without flinging you around. ive looked into constraints/constraint relaxation, and that seems to be what i need. its quite complex ive found because it need to be taut above where the player is, and dangling below where the player is, but i think i can get it working. so my question is answered for now. thanks all!

1. 1
Rutin
39
2. 2
3. 3
4. 4
5. 5

• 14
• 18
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633360
• Total Posts
3011516
• ### Who's Online (See full list)

There are no registered users currently online

×