# Set Position of multiple bodies

I have a character composed of five bodies which are tied together by a lot of joints. On of them is the overall chassis, to which all forces and impulses are applied to move the whole Character.

All in all that works very fine, except one thing: I need to set the Position of the Character so that it get Beamed from one place to the other in one single frame.

Unfortunately I cannot get this to work. I tried the following code, without any success…

playerbodies.forEach(function (bd) {
bd.SetLinearVelocity(new b2.Vec2());
var t = bd.GetTransform();
t.p.x -= 10;
bd.SetTransform(t, bd.GetAngle());
});


How can I make that happen?

• What do you mean by "without any success"? Apr 22 '14 at 19:33
• total crash, or the body move to somewhere and is left with strange movements… Apr 22 '14 at 19:46
• Please don't edit your solution into the question; rather, post it as an answer, since it is an answer to your quesiton. (Also, don't edit [Solved] into your title - this is not a forum.) Apr 23 '14 at 12:51
• Google "box2d teleport". I am sure you will find your solution. Oct 21 '15 at 8:28

As suggested in the comments… The answer is quiet simple and the right code is:

1| playerbodies.forEach(function (bd) {
2|     bd.SetLinearVelocity(new b2.Vec2());
3|     var t = bd.GetTransform();
4|     t.p.x -= 10;
5|     bd.SetTransform(t.p, bd.GetAngle());
6| });


whereby line 6 is corrected with t.p.

Since Javascript is not typesafe this mistake totally broke the simulation of the bodies, instead of throwing an error.