Skip to content

CircleHitbox doesn't scale #3508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task
gnarhard opened this issue Feb 23, 2025 · 0 comments
Open
1 task

CircleHitbox doesn't scale #3508

gnarhard opened this issue Feb 23, 2025 · 0 comments
Labels

Comments

@gnarhard
Copy link
Contributor

gnarhard commented Feb 23, 2025

What happened?

When scaling a CircleHitbox, the debug lines make it look like it scaled correctly, but collisions don't register in the bounds because the hit box didn't scale.

What do you expect?

CircleHitbox should scale.

How can we reproduce this?

No response

What steps should take to fix this?

No response

Do have an example of where the bug occurs?

void main() {
  runApp(
    const MaterialApp(
      home: GameWidget.controlled(
        gameFactory: _MyGame.new,
      ),
    ),
  );
}

class _MyGame extends FlameGame with HasCollisionDetection {
  @override
  Future<void> onLoad() async {
    camera = CameraComponent.withFixedResolution(width: 640, height: 360);

    await world.add(
      _MyCircleComponent(BasicPalette.white.color.withAlpha(100),
          BasicPalette.red.color.withAlpha(100),
          radius: 20, anchor: Anchor.center)
        ..add(
          MoveByEffect(
            Vector2(50, 0),
            EffectController(
              duration: 2,
              alternate: true,
              infinite: true,
            ),
          ),
        ),
    );

    await world.add(
      _MyCircleComponent(
        BasicPalette.green.color.withAlpha(100),
        BasicPalette.blue.color.withAlpha(100),
        radius: 20,
        anchor: Anchor.center,
        position: Vector2(80, 0),
      )..add(
          ScaleEffect.by(
            Vector2.all(2),
            EffectController(
              duration: 2,
              alternate: true,
              infinite: true,
            ),
          ),
        ),
    );
  }
}

class _MyCircleComponent extends CircleComponent with CollisionCallbacks {
  final Color color;
  final Color hitColor;

  _MyCircleComponent(this.color, this.hitColor,
      {super.position, super.radius, super.anchor});

  @override
  Future<void> onLoad() async {
    super.onLoad();
    paint.color = color;
    await add(CircleHitbox()..debugMode = true);
  }

  @override
  void onCollisionStart(
      Set<Vector2> intersectionPoints, PositionComponent other) {
    paint.color = hitColor;
    super.onCollisionStart(intersectionPoints, other);
  }

  @override
  void onCollisionEnd(PositionComponent other) {
    paint.color = color;
    super.onCollisionEnd(other);
  }
}

Relevant log output

Execute in a terminal and put output into the code block below

Output of: flutter doctor -v

Affected platforms

All

Other information

No response

Are you interested in working on a PR for this?

  • I want to work on this
@gnarhard gnarhard added the bug label Feb 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant