rope swing suggestion

I’d like to ask for suggestions on how to make the logics for the swing of the rope.

suppose the player is holding a rope, so when he presses right arrow, the rope should go right and than return, so the player must hold right, then left, than right, …, until he is as fast as he wants to jump out of the rope.

I have tried a lot of logics but all lead me to bugs and I think it got too much complicated for me to debug and I came to ask for suggestions about some good logics to implement.

PS: I chose not to send my current code as it is 103 lines long and it isn’t working properly.

Well, in this case the simplest solution is probably to use the physics engine.

(People who know me well are gasping in surprise at this point.)

Make a chain of joints, and when the left or right arrow keys are pressed, apply a corresponding force to the end of the chain. That should be enough to get it swinging in a natural way.

I know and I’ve done exactly that, the problem is the logics behind WHEN I can press right arrow to add some force in right direction, for example (it cannot be always, cause the player would stay in the end-point of the swing or do some non-natural movements).

Maybe you’re applying too much force, then? It’s true that the force is like a little rocket engine, and if it’s strong enough to counteract the force of gravity, then yeah, you could hover at the end-point of the swing.

But if it’s not that strong, then this wouldn’t work… you would settle back down to the fully-extended position (just with a little less tension on the rope). So then the player would be forced to work with the swing, building it up gradually.