When using MouseConstraint to interact with bodies that have constraints attached, it seems like the forces applied by the MouseConstraint are not being applied to the point where the constraint attaches to the body but to the body center.
Example 1:
var boxA = Bodies.rectangle(400, 200, 400, 200);
var constraintA = Constraint.create({
pointA: { x: 400, y: 200 },
bodyB: boxA,
pointB: Vector.create(0, 20), // Pivot point slightly below the center
stiffness: 1,
length: 0
});
The expected behavior is that when I grab the box on its right side and pull it straight down, I would expect it to start turning clockwise around the pivot point defined in pointB. However, boxA does not rotate when pulled straight down, but only starts turning if I pull it slightly to the left or right. Here‘s a video. This behavior is unexpected, and it seems as if the forces applied by the MouseConstraint are being applied to the center of the box rather than the point where the constraint attaches.
Example 2:
var boxB= Bodies.rectangle(400, 200, 400, 200);
var constraintB = Constraint.create({
pointA: { x: 400, y: 800 },
bodyB: boxB,
pointB: Vector.create(0, 0), // Pivot point at the center
stiffness: 1,
length: 0
});
In this situation, the pivot point is at body center. I would expect the body to start rotating when pulled but instead it does not rotate at all. This seemingly confirms my assumption that the MouseConstraint forces are applied at body center.
Am I missing something? Is there another way to get the result I’m expecting?