Skip to content
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

feat: MoveAlongPathEffect should maintain initial angle of the component #2835

Merged
merged 26 commits into from
Nov 10, 2023

Conversation

ivanfemia
Copy link
Contributor

@ivanfemia ivanfemia commented Nov 2, 2023

Description

See #2833

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

Related Issues

Closes #2833

@@ -85,7 +85,8 @@ class MoveAlongPathEffect extends MoveEffect {
'An `oriented` MoveAlongPathEffect cannot be applied to a target that '
'does not support rotation',
);
(target as AngleProvider).angle = _lastAngle = -start.angle;
_lastAngle = -start.angle;
(target as AngleProvider).angle += -start.angle;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct, since followAngle is true, it should be following the angle of the effect, and not be affected by what its current angle is?

Copy link
Contributor Author

@ivanfemia ivanfemia Nov 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well the problem is with the preexisting angle of the component, in the current release this is always initialized to the tangent. It should consider the angle of the component itself. Please have a look to the test code in the issue #2833.

(Example) I want a Rect to be 45 degrees turned (rhombus) and then use the vertex as the head to follow the path, currently the Rect is always following the path using one of the sides. In the example linked I used a Polygon with 3 vertex.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then you should be using nativeAngle to set that, not angle.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, we can close this as intended behaviour

@ivanfemia ivanfemia closed this Nov 3, 2023
@ivanfemia ivanfemia reopened this Nov 6, 2023
@ivanfemia
Copy link
Contributor Author

@spydon Coding style preference


      (target as AngleProvider).angle = (target is PositionComponent)
          ? -start.angle + (target as PositionComponent).nativeAngle
          : -start.angle;

instead of

(target as AngleProvider).angle = _lastAngle = -start.angle;
(target as AngleProvider).angle += (target is PositionComponent)
          ? (target as PositionComponent).nativeAngle
          : 0;

Removing import as now included in the component
New line to stay in the 80 columns line lenght
@spydon
Copy link
Member

spydon commented Nov 6, 2023

@spydon Coding style preference

I think it is even clearer to read it if you separate them and just do:

final _target = target;
(_target as AngleProvider).angle = -start.angle;
if(_target is PositionComponent) {
  _target.angle += _target.nativeAngle;
}

Copy link
Member

@spydon spydon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm, only a variable name change needed I think!

packages/flame/lib/src/effects/move_along_path_effect.dart Outdated Show resolved Hide resolved
@spydon spydon merged commit e6e78c0 into flame-engine:main Nov 10, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MoveAlongPathEffect oriented should keep inital angle of the component
2 participants