Making a realistic rope that's attached to the grappling hook


(An example of how i want it to look)

I’ve already done the grappling hook mechanic and it works fairly well. Now only thing it’s missing is it’s rope. I know i can just use a shape painter to draw a rope in between but i want it to be realistic being able to interact with objects etc. How can i do that? I know how to do it with already in scene sprites connecting the pieces to each other but constantly creating AND connecting them to each other is a head scratcher.

A thing to note :
Head of the grappling hook is not instant as in it doesn’t instantly connect to any surface. It’s a projectile that flies until it collides with an object. I want the rope to be attached to the arm and the grappling hook and expanding as long as the hook is flying

So here’s the idea: When your grappling hook hits something, store that collision point as the “grabbed” spot. Now, as your player moves around, you want to check if there’s still a clear line between the player and that spot. That’s where raycasting comes in — shoot a ray from the player to the grabbed point. If the ray gets blocked (like by a wall), boom — that’s your first breakpoint in the rope.

From there, you draw the rope using the Pen:

  • First from the grabbed point to the breakpoint
  • Then keep checking visibility from the player to that breakpoint
  • If that gets blocked too, add another breakpoint
  • Keep repeating as needed

This way, your rope bends and wraps around obstacles naturally, instead of just being a straight line. It’s a bit of logic juggling, but once it clicks, it’s super satisfying.

You could even store those breakpoints in an array so you can redraw the rope every frame. And if the player moves back into line-of-sight with a previous point, you can clean up the rope and remove extra bends.

Hi @GrocKing - so do you not want to do it with a chain of objects? I was thinking a numbered chain of objects.

Since the grappling has no limit numbered objects won’t work sadly

Hmm that’s an interesting idea. Though the hook sometimes acts weirdly like there is already a wall inbetween the hook and the player. Hook itself digs into the objects. I’m not using specific grappling points but rather all platform objects. Even though i have “stop” command in the code it just sometimes digs in (which i don’t mind it does look as a proper intended hook similar to just cause)

I can put the code here if you want to take a look at how it works. Though it can be a bit confusing because it does talk with other mechanics aswell

Well in that case, you can check the distance btw the raycast point and the hooks point. and check if its a relatively low value. Id also like to see the code













And the parts where it talks with other mechanics


These ones are basically for overriding animations though. Basically patching up the bugs that come along the way.

It’s pretty long but the stuff i want it to do is also pretty long lol.

  • Character aims the grapple first (time scale goes down by half if the character stars aiming mid air)
  • Shoot the grapple, it connects and then character starts swinging
  • A/D to swing left and right (simulated with physics)
  • In order to get out you press space and after the jump you can also double jump (also simulated with physics)
  • Character is static when not grappling (using platformer behaviour to move around)
  • When swinging platformer behaviour gets disabled and character becomes dynamic. In order to stop the character from spinning around there is a rotation code that’ll keep the character straight.
  • There are also other stuff like bouncing off walls etc. Used collision on that one instead of adding physics to walls. Using physics once seemed to make the hook get stuck in which made the rope also stuck and caused swinging so i just mixed all together using grouped objects.

I know these. Making them connect when they’re already in the scene i can do. Problem is creating and THEN connecting them seperately (like x connects with y and y connects with x and z and then z connects to x and v)

I’ll try what @dskyle7 suggested later on and see if that works. Also seems to be simpler than just constantly creating 1px height objects. Collision on the walls etc. on the part hook is digged in could be an issue but i’ll also try his suggestion just adding distance parameters like 5-10 pixels to see if it’ll do the job

If its possible to do it in editor its possible to do it via events
YOu have logic there so all you need is creating them and giving them proper variables

I am looking at vines scene and its empty

Then i look at its events
And seems here is your answer

Does my example of rope physics meet your needs?

Nice example project - @GrocKing needs it to stretch and there is a bit of give in the links but I just tried adapting it a bit to set the link 1 length to the distance to the next link - I needed to use pick nearest as they’re not numbered so it didn’t quite work but I think this could be adapted into a stretchable chain of objects that’s created with a repeat event when needed.

Look at this part
image
It creates it 5 times and uses collision to connect them. But that actually gives me an idea i can try using collision for it and see what happens aswell.

I’ll see to this one first and then if it doesn’t work i’ll try the raycast idea.

I’ve checked that one out actually that was the thing i was talking about in the post that objects that are already scene i can do but making a dynamic one was a head scratcher. Got some ideas from the replies now and i’ll give them a go today

1 Like

A bit of an update:

@ZeroX4 Went with yours first but failed at the first try. Both the rope object and the character have physics behaviours so they just end up constantly colliding. There is also the part where i have trouble connecting the rope to the arm since arm itself doesn’t have any physics behaviour aswell (so the arm can collide with character freely)

@dskyle7 Tried to work on your idea but kinda stuck on that one too. Shape painter somehow “lags behind” the characters arm when swinging
image

Not sure what to do here now honestly

If the character’s animation isnt much, you can try giving a custom point for each of the frames at the point where the arm is. then use that point as a starting point for drawing

If shapepainter lags behind then its either issue with order of events if not with proper position

Arm doesn’t really have an animation for the rope no it just angles itself towards the hook

Not really no. Put it at the end of it but still lags behind. Not sure why

This is what I think you should do.

  • First check if the shape painter is at position 0,0 of the screen.
  • secondly, make sure it updates every frame.
  • Finally make sure the point where the painting starts from is positioned correctly in the spite’s character point

Event to change position
Should be ABOVE event to draw shapepainter

Shape painters position has nothing to do with the drawing. The tick for it is unchecked (also you need to uncheck that to make it work more or less it won’t work even if you change shape painters position)

The line that’s drawn is always from the fire point of the arm and the hook. Nothing changes

I’ve just said that? : D