2

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?

Panda Pajama
  • 13,395
  • 4
  • 44
  • 77
philipp
  • 389
  • 1
  • 15

1 Answers1

0

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.

philipp
  • 389
  • 1
  • 15