- Home /
Tying two players (Rigidbodies) together with a rope
I have two capsule colliders with rigidbody components. 1 capsule is controlled by Player one, one capsule is controlled by Player 2 - movement is fairly simple, just flying around in zero gravity, X&Y axis only.
I am trying to tie the character together with a rope. This means:
There should be a maximum distance which they can travel from each other.
The rope should be physics-based and collide with objects in the environment.
(If I can only get the first bullet point, I can attempt to design the game around that - but I'm really trying for both features).
I will describe my current implementation and failures in the comment. Thank you.
I've tried modelling a rope off of several different online references, but nothing works well when the rope is being pulled at both ends. Right now, my most successful attempt, is creating a string of small capsules between the players, each with rigidbodies and configurable joints (basically a manually-constructed chain).
This chain starts at player one, which appears to work fine while dangling free. However, I had to enable Projection $$anonymous$$ode: Position Only to keep the chain together (if anything tugs on the end, it just stretches infinitely, which also makes it get stuck around other objects if it bends around them while stretched).
Problems with this set up:
The Projection $$anonymous$$ode snapping, ins$$anonymous$$d of stopping the player object, will just snap the chain to the player - making the chain just move straight through walls/etc.
When Player 2 is attached to the end of the rope, Player 1'2 motion (being higher up the chain) "overrides" Player 2's attempt at motion if both players tried to move in opposite directions.
If #1 is enough, you could just constrain the movement of players so that they're never too far apart. Here's some pseudo code:
in player.move()
HandleInput
if( currentPosition + movementIncrement > otherPlayer.position + ropeLen)
currentPosition = otherPlayer.position + ropeLen;
Thanks for your response, perchik. I am attempting to get a solution like this working, at least until I can find a physics-based rope that works.
Just have a bit of a snag, as everything is physics-based, and movement is done by rigidbody.AddForce().
Currently, I am using a separate ConstrainPlayers script and it kind of does what I want - when the characters get too far away from each other, I can successfully detect that and somehow put a stop to it.
But, I haven't figured out a good way to stop them and bring them back toward each other, and to make sure the proper force is applied to both players in a workable fashion.
Answer by lancer · Sep 13, 2013 at 03:56 PM
If you have money to spend you can buy "QuickRopes" off the asset store.
The bridge demo seems to have the behaviour that I want, but this project is only for a 48 hour game jam, trying to avoid spending $15 for a plugin (particularly when I don't need all of the features).
I'm also a little worried that I would run into the same inherited-motion issue with this plugin, and obviously I can't test it before purchasing. I will try to contact the creator of the plugin.