'Unable to move localAnchorB body in RevoluteJoint if Vector2(0,0)
In the following RevoluteJoint, if I set localAnchorB to Vector2(0,0) Then I am unable to drag the Component with MouseJoint.
But If I set it to just Vector2(0,0.1) I can start to drag it around the point.
And setting the motor also works with Vector2(0,0).
Note: BaseBox is just a BodyComponent with a MouseJoint, so I can drag around and reuse. I am not including the MouseJoint for simplicity and the fact it works setting localAnchorB to Vector2(0,0.1).
class Box extends BaseBox {
BaseBox? boxToAnchor;
Box(position, paint, [this.boxToAnchor]) : super(position, paint);
@override
Body createBody() {
super.createBody();
if (this.boxToAnchor != null) {
this.boxToAnchor!.priority = 1;
priority = 0;
body.setType(BodyType.kinematic);
final revoluteJointDef = RevoluteJointDef();
revoluteJointDef.bodyA = body;
revoluteJointDef.bodyB = this.boxToAnchor!.body;
revoluteJointDef.localAnchorA.setFrom(Vector2(2, -2));
revoluteJointDef.localAnchorB.setFrom(Vector2(0, 0)); // No problem with Vector2(0,0.1)
/* revoluteJointDef.enableMotor = true;
revoluteJointDef.motorSpeed = 2;
revoluteJointDef.maxMotorTorque = 1000;
*/
RevoluteJoint joint = RevoluteJoint(revoluteJointDef);
world.createJoint(joint);
}
return body;
}
}
Example 1
With revoluteJointDef.localAnchorB.setFrom(Vector2(0, 0));
Example 2
And with revoluteJointDef.localAnchorB.setFrom(Vector2(0, 0.1));
The closer Vector2(0, 0.1) gets to Vector2(0, 0) the more responsive.
Example 3
And using motor with revoluteJointDef.localAnchorB.setFrom(Vector2(0, 0));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|



