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?

  • \$\begingroup\$ What do you mean by "without any success"? \$\endgroup\$ Apr 22, 2014 at 19:33
  • \$\begingroup\$ total crash, or the body move to somewhere and is left with strange movements… \$\endgroup\$
    – philipp
    Apr 22, 2014 at 19:46
  • 2
    \$\begingroup\$ 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.) \$\endgroup\$
    – Doorknob
    Apr 23, 2014 at 12:51
  • \$\begingroup\$ Google "box2d teleport". I am sure you will find your solution. \$\endgroup\$
    – Engineer
    Oct 21, 2015 at 8:28

1 Answer 1


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.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .