10 – Finetuning Rope Swinging

So last time the base rope from the tutorial was done but there were a few issues:

1. Rope can be deployed everywhere
2. The rope can be seen through the 2DDL lighting shadows
3. The rope prevents normal movement

As this is the gameplay prototyping module I focused on the aspects that affected gameplay, namely issue 1 and 2.

This was the most difficult task to do so far as it required me to essentially go out and experiment on my own with very little from help tutorial (not for the lack of looking there just wasn’t any that did it the way I wanted to)


Fixing Issue 3 – Rope prevents normal movement

This was easy enough as I realised it had more to do with the physics of the game than the actual code: essentially the combined mass of the rope (aka the nodes who have Rigidbody2D) would be too great and prevent movement. This wasn’t a problem for short ropes (aka few nodes meaning lower mass) but for long ropes like the one in the video this can be a problem.

After playing about with changing the Rigidbody2D masses of both the nodes and the player (as well as gravity scale) I settled on simply changing the ropeNode prefab’s mass from 1 to 0,1, after all, its so easy to change and play about with that if I changed my mind it would take less than a second.


Fixing Issue 1 – Rope can be deployed everywhere

This issue was my toughest problem to boot and required a lot of research and trial-and-error.

My core fix was essentially to limit the player’s rope swinging to only the platforms (aka no mid-air). To do this I had to work with and modify the existing code.

How the rope code works:

  • the player mouseclicks a location
  • a ropeHook obj is spawned and made to go to the mouseclick
  • nodes are created as the ropeHook travels through the air as well as after it hits its target
  • the nodes are attached to the player
The Failed Attempt
My first attempt failed as I tried to accomplish too many things at once:

  • I wanted to fix the issue
  • I wanted to revamp the way the rope is shot (from mouseclick to an aimed projectile similar to Angry Birds or an Archer shooting an arrow)

While I learned a lot during my research the attempts led to nothing as the existing rope code (hookRope script, the one making nodes) was fixed on the way the rope was deployed: a literal movement of the ropeHook to the fixed target point – whereas I wanted to make a physics-based projectile just shot at the general distance not towards a point.

The Successful Attempt
I lowered my scope a bit and focused on the problem at hand: the rope can be deployed everywhere.

After some more exploration I ended up with this:

  • the ropeHook still goes after a hookTarget but
  • if the ropeHook collides with an object tagged with “Platform” it sets its current position as the new target (which makes it stop moving and attach itself to the player)
  • if the rope doesn’t hit a “Platform” but reaches its hookTarget


I used the (hookAttached) boolean as a workaround to check if the hook actually hits a collider/platform.
While this sorted the main issue the manual destruction of the rope with Destroy(this.gameObject) within the hookRope Script meant the same rope object’s state of existence was being handled by two scripts: the initial hookThrow and now hookRope.

The hookThrow Script is what what handles the deployment and prevention of duplicate ropes and because of the new code: doesn’t actually know that the rope is destroyed. This meant that the player would have to click twice to deploy a new rope instead of clicking once like before.


This function lies within hookThrow’s Update and essentially checks if there’s any ropes around working as an extra-check and failsafe for any rope’s existence.

New Platform Prefabs

To make the hook actually register collisions with the Platforms I had to make a child gameObject on the Platform called TriggerCollider (as it previously only had Effector colliders)


No video this session as its pretty much a rope being destroyed if it reaches the mouseclick point and doesn’t collide with anything – it’ll be seen for sure in the next video!

Leave a Reply

Your email address will not be published. Required fields are marked *