Alternatives to HingeJoint with more flexible movement

Hi all,

I’m trying to write a grappling hook/rope swing mechanic for a prototype game idea. The basic concept is a 2D side scrolling game where the player aims at the ceiling to plant a hook, and he can swing from that anchor point. It looks like this:

Currently it is somewhat working (uploaded current build here). The basic algorithm I am using looks something like:

  • Cast a Raycast2D from player in the direction of the mouse position when mousebutton is pressed
  • Create a HingeJoint2D
  • Set HJ2D.connectedAnchor at the RaycastHit2D point
  • Set HJ2D.anchor also at the RayCastHit2D point (converted from world to local space)
  • While it is swinging continuously decrement HJ2D.anchor x and y to get close to 1 to make the player ‘Pull’ himself towards the anchor point
  • When mousebutton is let go, destroy the HJ2D

Full code here

Unfortunately there is a major flaw with this method in that when the player casts a hook directly above him, and he is not swinging, he will pull himself up but no force is created, so when you release the hook he falls straight down instead of continuing to go up, and letting gravity eventually. While he is swinging with reasonable speed, this isn’t so much of a problem.

Is there something I can change/add to make this work? What other methods can I use to achieve this mechanic?

I realize this is a pretty old thread, but I just played your game and I think its fine as it is. Rename it something like “grapply boy” and release it on IOS. Its better than Flappy Bird.