Change length of rope constraint using Lua

I’ve just published a small tool (weapon, really) that lets you turn yourself into a ragdoll and rope yourself to the target.
It all works fine, you can ragdoll, unragdoll, swing around and stuff.

At the moment the length of the rope is set as the distance between you and the target. What I need some advice on is how to change the length of the rope dynamically using Lua.

The rope is created using constraint.rope() which returns a phys_lengthconstraint and a keyframe_rope

I have tried using SetKeyValue() with combinations of ‘Slack’, negative ‘addlength’, and ‘length’ without any results.
The closest I got was increasing the ‘Slack’ on the keyframe_rope made the rope appear longer, but the phys_lengthconstraint didn’t get any longer.

I tried taking a quick look at a grappling hook weapon but instead of using constraint.rope() it used ents.Create and created a keyframe_rope and move_rope, and no phys_lengthconstraint (?) …

I would really appreciate if anyone could give me some pointers on how to change the length of the rope constraint using Lua. Thanks

Isn’t this basically what a winch constraint is?

I dunno, is it? I’ll have a look into how winch’s are made now

EDIT: Winch’s use elastics but I’ll see if I can modify it to use that without changing too much.

[editline]22nd July 2013[/editline]

(Does this automerge?)

Thanks for the suggestion of winch, I looked up how winches are made in the constraint library, it uses elastic constrains and an entity called gmod_winch_controller. The winch controller eventually calls:
[lua]self.constraint:Fire( “SetSpringLength”, current_length, 0 )
if ( self.rope ) then self.rope:Fire( “SetLength”, current_length, 0 ) end[/lua]
Seems it calling :Fire() instead of :SetKeyValue(). Before changing to elastic/winch I’ll first try using :Fire() on the rope and constraint I have.
Not sure what to Fire() on the phys_lengthconstraint I have though. “SetLength” ?

[editline]22nd July 2013[/editline]

phys_lengthconstraint doesn’t have any input to fire to set the length. Looks like I’ll have to change to the winch / elastic.

Will give it a go once I get home.

I’ve managed to get the rope to be an elastic that can change what its set length is, but it doesn’t behave exactly like a rope. I hope I just need to find the right constant and dampening for it.

If anyone knows what settings to give an elastic to make it identical in behaviour to a rope then this will be solved. I’ll be working away at it and will report back if I find the answer.