2D GRAPPLE GUN QUEST: ‘Modify our Joint Anchor’ - Solutions

Quest: 2D Grapple Gun Quest
Challenge: Modify our Joint Anchor

Feel free to share your solutions, ideas and creations below. If you get stuck, you can find some ideas here for completing this challenge.

I couldn’t figure out the hint with transform.localScale, but a little googling led me to this solution which seemed to work perfectly

joint.connectedAnchor = hit.transform.InverseTransformPoint(hit.point);

I understand that InverseTransformPoint converts the raycasts world coordinates to the localcoordinates required for the connectedAnchor.


I have to admit, this kind of thing is my weakest area in Unity, from the hint given I thought this would be the solution:

joint.connectedAnchor = new Vector2(hit.transform.localScale.x, hit.transform.localScale.y);

but that doesn’t work. Thanks for @Kosmic for the solution as this one had me stumped.

“A solution”… :stuck_out_tongue_winking_eye:

I went
joint.connectedAnchor = hit.point;
and removed the connectedBody we added earlier

{Something like that anyway (I did it a couple of months ago) and change quite a bit to get a game out of it}


I used @Kosmic solution

Thanks Kosmic! Was starting to go bald scratching my head lol.

Yes, thank you. This one line seems to have fixed all issues in the quest. Even the next challenge ‘Keep on swinging’ has been resolved. Brilliant

I tried this out too. I don’t really understand why removing the connected body makes it work.

Not sure if you were still trying to figure it out, but without the Rigidbody Unity automatically interprets the connectedAnchor as world coordinates.

From the Unity docs on connectedAnchor:

“The position is given in local coordinates of the connected rigidbody, or in world coordinates if there is no connected rigidbody.

So with no Rigidbody attached to interpret the point locally, it uses world coordinates and works. And you also don’t need the reference at that point because you have already performed the check to make sure you’re targeting a Rigidbody in the if statement above.

Hope that helps clarify things.

Privacy & Terms