flameforge2d

Forge2DGame: No effect setting - body.position.setFrom(info.delta.game)


From this example you can drag around(not at the draggable point but some factor) a BodyComponent by setting body.applyLinearImpulse.

If I try to drag around, setting body.position I get no effect. I was hoping to be able to drag the BodyComponent around at the specific drag point.

Sample code line 37:

  @override
  bool onDragUpdate(DragUpdateInfo info) {
    // final worldDelta = Vector2(1, -1)..multiply(info.delta.game);
    // body.applyLinearImpulse(worldDelta * 1000);
    body.position.setFrom(info.delta.game);
    return false;
  }

Solution

  • You should never manipulate body.position directly, since that could break the stability of the physics engine.

    For your use-case you probably want to use a MouseJoint instead:

    https://github.com/flame-engine/flame/blob/ba617790e4a7ca4dc03f4a2e29de43d42efd3482/packages/flame_forge2d/example/lib/mouse_joint_sample.dart