#How to make Grapple hook

1 messages · Page 1 of 1 (latest)

viral sorrel
#

for some context, I'm making a 2d platformer game, it doesn't matter what the game is but I'm looking for a good tutorial with a good grapple hook. But when I say grapple hook, I mean the swinging kind, not the one where I zip to the direction I shoot, but when I shoot it, I swing with velocity and whatnot. I would also like a tut that uses godot's movement template or at least expands on it. Thank you!

hybrid yew
#

You can use a textured Line2D for the grapple line, starting with your player and leading to the current position of the grapple.

For the swinging motion, you can temporarily swap your player with a RigidBody2D version and attach it to a hinge. The hinge should include the RigidBody2D and a temporary StaticBody2D (the static body goes where the grapple landed).

#

You could then update the player movements to add linear velocity left right to 'swing'. downside of this method is the rope is going to be very straight, but if you want to go all out you can use multiple links in the chain.

#

The 'hinge' is up to you, but for this I'd recommend a DampedSpringJoint2D node.

viral sorrel
#

I am beginner and do not know how to code that and I just want a tutorial

hybrid yew
#

How new are you? If you're just starting out it might be best to get the basics under your belt. If you have a bit of experience though, then just check the DampedSpringJoint2D documentation. It's really easy to use. Just set your nodes and it'll do all the hard work for you.

#

Afaik there's no specific grappling hook tutorials yet. Maybe I'll make one if the mood takes me.

brazen lotus
# viral sorrel I am beginner and do not know how to code that and I just want a tutorial

Also a beginner here, I just watched this video where he goes over all the 2D nodes, honestly was really helpful to see them in action, check out the DampedSpringJoint2D section there should be timestamps in the comments

https://www.youtube.com/watch?v=22VYNOtrcgM

viral sorrel
#

I’ve watched it but I’ll have to rewatch it, thanks!

fossil rune
#

you can do it way easier by just instantiating a whole pendulum when you activate the grapple hook, and you match player's pos with the pendulum pos

#

this way you can code the grapple itself with all the movement and just match the player pos

#

you can cast a ray in the aiming direction to obtain a point, and a distance between the player and that point

#

or a weirder implementation, you shot an invisible projectile (limited to 1)
and a line will permanently connect the player and that projectile

#

to get the rope feedback

#

and when it hits an object then you know you connected and instantiate the swinging part

hybrid yew
fossil rune
#

you can have a dummy holder instead of the player that swings with the hook

#

and you just keep the player snapped to the dummy position until release

#

draw this quick example xd

#

shot a projectile to a wall and then when it hits you spawn the yellow pendulum

#

and keep the player pos snapped to the yellow pos until release

#

when you release, you transfer the force from the yellow dot to the player

#

ofc you can have the projectile and pendulum hidden

#

and only draw the rope between the points

hybrid yew
#

Yeah, basically sounds like my suggestion, but with a slight variation. I'm going to mock up some code. Should be fun. I'll post the result.

hybrid yew
#

Scene tree:

#

Ignore the leading/trailing apostophes. Tried sending it in code format, but it was a little too big. Delete them.