Sign in to follow this  

Grappling Hook Code

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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!

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this