Propagating collision impulses among multiple objects.

I am trying to construct a game where the player can split into several "coupled instances" of himself, essentially controlling two (or more) objects simultaneously. The twist is that I want the objects to share movement, in short: If one instance can't move in a certain direction, none can, if one collides with a box, all fly backwards.

Also, we want to be able to rotate the coupled instances, having them move in different directions, so just connecting them with joints would not work (as far as I know).

It seems like this could be done by giving all instances of the player separate bodies, and propagate the impulses from postSolve between them.

This is part of my code in postSolve: (I am using the svn-version of pybox2d)
Code:
for f in [contact.fixtureA, contact.fixtureB]:
    if f.userData["type"] is not "player":
        continue
    for o in f.userData["parent"].objects:
        if not o.body.fixtures[0] == f:
            m = contact.worldManifold
            o.body.ApplyLinearImpulse(impulses.normalImpulses[0]*m.normal,
                                      o.body.worldCenter + contact.manifold.points[0].localPoint)
The parent object (f.userData["parent"]) contains a list of all coupled instances of the player. I only use the first element of impulses.normalImpulses (a tuple with two elements). With fixedRotation on (which I have), the second element seems to stay constant at -1 (not sure why).

Split a player into two coupled instances (controlled by the same keys) and let one of them run into a wall. The other instance will slow down, but still move. It seems like the normalImpulse given by postSolve is not quite enough to make it stand still.

Any help and/or insight into how postSolve works would be appreciated, as well as other ideas on how to achieve the wanted behaviour.
Sounds like a fun game!
The behavior you describe sounds almost like a single large body with the players as fixtures attached to it - is that a possibility? If they players need to rotate independently you could join them to the large body with revolute joints.
Hmm.. but I don't understand how you would "rotate the coupled instances, having them move in different directions" while at the same time, "if one instance can't move in a certain direction, none can"... seems like a contradiction.
It does sound like fun doesn't it 🙂

Fixing the two instances as fixtures to a body is not really feasable for the same reasons that a joint is unusable.

Basically, when a player is rotated so is his gravity and movement direction. In other words, a player rotated 90 degrees falls to the right, moves upwards when the player presses right and stands firmly on vertical walls.
Actually now that you've clarified that, it seems like something that would really mess with my head 😀
About implementing it, I think you will indeed need to do some trickery like with your PreSolve method - exactly how I'm afraid I can't envision too well. One thing I did think of though looking at your code, was that you probably should transform the contact.manifold.points[0].localPoint using the body's transform to get it into world coords before you add it to o.body.worldCenter to use as the impulse location.
I read your question yesterday, and I have been thinking...

An idea I had was to create as many as needed helper bodies. All with sensor fixtures, so they won't collide with anything. These helper fixtures are meant to create a stable construction, connected with distance joints.

So, when you have to duplicate your player:
Code:
     X
    /  \
  P --- P
Where X is the helper body and P the players. This causes a strong construction.

For four player maybe something like this:
Code:
     P
  /  |  \
P -- X -- P
  \  |  /
     P


And you can make it World of Goo-ish by setting some damping to the distance joints, which might be pretty cool!

What do you think?
Yeah, that idea has struck me (or us, as I should say since this is a two-man project), but unless I misunderstood your comment, I don't think a joint-based solution is possible for the same reasons I detailed in my earlier post (basically, we want to be able to have two instances of the same player oriented differently, but affected by the same (rotated) impulses).
Bump, and quick update.

We have been trying to solve the problem by taking the impulse acting on an object from PostSolve and applying that to the objects coupled instances.

In the case with two coupled objects of which one has a wall infront of it, and a constant force applied to both wants to move them forward, we want both objects to ideally stand still, since the walls action on one object should be copied to the other. However, the second object (the one not colliding with a wall), slows down but keeps moving in the direction of the applied force.

This probably stems from us taking the impulses from PostSolve, after they have been applied, and using ApplyLinearImpulse to copy them to other coupled objects. The "copied" impulses won't act until the next world.Step(), and therefore always lag behind.

From here, we don't know where to go. Any ideas would be appreciated, but note (as has been said above) that since we want the objects to be able to move in different directions, joints will not do the trick. Unless joints can be used in some weird way we don't know about.
Bumping this, to see if any new inputs can be given.
bump

Original thread: https://box2d.org/forum/viewtopic.php?t=7275