2d Grappling Hook, where do I start?

Godot Version

v4.3.stable.official [77dcf97d8]

Question

Hey everyone!
I’m trying to build a grappling hook system for a 2d platformer. It seems like i’m trying to do it in a way that not many others are approaching it. Not positive I can embed images here, but if it helps, I’m controlling a robot on one wheel that has a claw sprite visible on it at all times, which currently rotates to follow the mouse using the look_at() function. I’m trying to make it so the claw can fire out to a maximum distance (which can be increased with upgrades, not yet implemented), grab virtually anything, moveable or not, and be reeled back in with the scroll wheel. So the line, rope or chain, or whatever it ends up being that connects the claw to the robot will need to form itself to physics so it can be slung down a ledge for example…

I’ve been spitballing and googling like crazy to just find a starting point, but can anyone at least get me pointed in the right direction as to how to start building this system? I’m fairly new to game dev and my only coding experience is some Front end Web Dev, so mostly just HTML CSS and some JS vanilla.]
Thanks a bunch everyone!

I would start by using a RigidBody2D for the hook. You can disable gravity if you want. If the hook overlaps the player, I would make sure they are on different collision layers or disable the hook’s collision if it hasn’t been shot out yet (use collision layers so you can decide what objects the hook will hit). Then, when you shoot it, stop using look_at() and apply a force using apply_central_impulse() or apply_central_force(). Every frame, add the hook’s location to a list and set that list to be the points property of a Line2D that you can texture for the chain. If the length of that list is too high, you can pull it back using another force or something. Then, every frame, use get_contact_count to check if the hook has hit something. If it has, every frame, move the player towards the hook. If the player can’t move while the hook is shot out, you can just set the player’s position to be the positions stored in the list from earlier. Then, when the player is touching the hook, reset everything. I would recommend having some kind of hook_state variable to store whether the hook is held, moving, or attached to an object.

I’ll give this a shot and see, probably leave this thread open for a while. I don’t get much time to work on all this so ill implement it piece by piece when I can. Thanks for giving such detailed info!

I rope a static rope that a character can jump to and jump off, static i the sense that there is no movement in the rope, and it just move backward and forward, I am only a novice programmer. I could send that to you if it would help, but, you seem a little bit more advanced than me. But a grappling hook or a more rope-like movement is where I would like to get to. And it’s very basic. So, if I could help you out and then you help me, win-win.

Regards.