0

I have the following code to manually set the position of a (dynamic) object in a Box2D world (drawn with the help of EaselJS). Unfortunately setTransform returns this error.

Uncaught TypeError: Cannot read property 'position' of undefined 

This is the code

// during drag and drop
if(mouseJoint & isMouseDown) {
    mouseJoint.SetTarget(new b2Vec2(mouseX, mouseY));
    var body = mouse.getBodyAtMouse();

    if(body != null) {
        body.SetAngularVelocity(0);
        body.SetAngle(0);
        body.SetTransform(b2Vec2(10,10), 0);
    }

    ...
ios-lizard
  • 834
  • 1
  • 12
  • 19

2 Answers2

2

Solved by using

body.SetPosition(new b2Vec2(10,10));
ios-lizard
  • 834
  • 1
  • 12
  • 19
0

I'm no JS guru, but I suspect you need to use 'new b2Vec2' instead of just 'b2Vec2', in the same way as you have for the SetTarget call.

iforce2d
  • 8,194
  • 3
  • 29
  • 40
  • True! I now get "'undefined' is not a function (evaluating 'a.GetAngle()')", what should I pass as a second argument? – ios-lizard Sep 28 '12 at 01:21