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
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
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
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.
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
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.