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)
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.
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).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)
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.