I am using Box2D to simulate a small world where the user can drag objects and 'stick' them in some predefined locations (basically 'locking' them in a certain position).
I have this code to lock an object in a position. Everything works excepts I cannot make SetPosition (nor SetTransform) to work. They just move the object to (0,0).
FYI the world is drawn using EaselJS.
// checks if mouse is dragging the object nearby one of the containers
if( isWithin(mouseX, mouseY, containers) ) {
// make object 'straight'
body.SetAngularVelocity(0);
body.SetAngle(0);
// makes the object a kinetic body
body.SetType(b2Body.b2_kineticBody);
// doesn't work. it always moves the object to (0,0)
body.SetPosition(5,5); // I am using (5,5) for simplicity
// it should have the coordinates of the center of the container
// alternative: (also doesn't work)
//body.SetTransform(b2Vec2(5,5), body.GetAngle());
}
What am I doing wrong?