Kodeco Forums

Make a 2D Grappling Hook Game in Unity – Part 2

Note: This tutorial is intended for an intermediate to advanced audience, and won’t cover things such as adding components, creating new GameObjects scripts or the syntax of C#. If you need to level up your Unity skills, work through our tutorials on Getting Started with Unity and Introduction to Unity Scripting first. Welcome to the […]


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/312-make-a-2d-grappling-hook-game-in-unity-part-2

Thanks for this great tutorial. It let me discover new concepts & functions quite advanced (i guess), with a really fun outcome to play with, reuse, enrich :slight_smile:

I noticed a strange behaviour : in some cases, previous wrap points are removed before a new one is added , causing the rope to cut through the rock :

I added some debug, and also tried to call HandleRopeUnwrap() in LateUpdate() instead, but it seems that the new wrap is only added on the next frame, after removing the previous ones. Any idea why the wrap points value (1,-1) would change in those cases ?

Thanks in advance !

Got it : Vector2.Angle() returns an unsigned angle, never greater than 180.
So when we cross the 180 limit and compare playerAngle to 178 for instance, playerAngle becomes 179, 180, then back to 179, 178, 177 so UnwrapRopePosition is called

Here’s what I changed :

  1. I used Vector2.SignedAngle() for both angles instead, to get 179, 180 ,-179 (now the angles are different)
  2. before comparing angle, i add 360f to them if they’re negative (to get 181 instead of -179, which is still > to 178)

This seems to do the job but i guess it’s quite dirty. Please let me know if there’s an elegant way to fix this issue.

Thanks again for the tutorial :slight_smile:

Hi Sean - would it be worth it doing this effect with a tweening editor? Your opinion will be helpful…

@shogan Do you have any feedback about this? Thank you - much appreciated! :]

Hi @gkfr,

Thanks for spotting this and for finding the issue too. Your fix sounds valid to me, and I don’t see an issue there. Trick is to avoid the > which your addition of 360f is doing. I’ll have a look and see if we can update the code for this.

Cheers!

Hi @shaldarworx

Which effect do you mean?

The only bit I can think of that might benefit from using a bit of tweening (or easing) effect might be the initial rope firing out and hooking into the terrain.

You could certainly tween or ease that. I would recommend using something like HOTween which has a free version you could get started with.

Unless you mean something else?

Thanks!

You’re welcome :slight_smile:
Actually i kept playing / messing with this since my post (cuz ninja rope is so fun :smile:)

I also noticed that (unless i missed or changed something…), isColliding = true; is never called since the OnTriggerStay2D method from part 1 requires a trigger collider, and the player’s one is not (as it’s also used for it’s physics).
So we still can increase the length while on the ground for instance, sometimes causing the player to go inside the rocks, or the rope to stick to the ground like this
groundrope
But i’m not sure i’d use it that way anyway (as it would prevent player to reduce rope size to climb the side of a rock he’s colliding with right ?)

I also face similar behaviour when player is at high velocity (because of a long fall, or when i activate a bounce effect i tried to add), especially when the player is receiving horizontal input (i guess the movement is still applied right when we collide, so again we move “into” the rock. any tips on how to avoid that ?

Finally, if you plan to add a part 3 someday :grin:… i’d suggest a bounce effect. Because it’s fun, and egoistically because i’m having quite a hard time with those high speed cases, and finding how to determine a stable base force on the right side (i reused the perpendicular calculation, but i don’t always get the one i’d expect based on collision direction)

Regards

This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!