fix: Absolute angle takes into account BodyComponent ancestors too #2678
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Currently, the implementation of the
absoluteAngle
getter inPositionComponent
only takes into accountPositionComponent
ancestors. The implementation simply runs through the whole hierarchy summing up the relative angles.This gives a wrong result with Forge2D because
BodyComponent
s have angles too: in the common situation where aPositionComponent
(e.g. aSpriteComponent
) is the child of aBodyComponent
, theBodyComponent
's rotation is ignored when computing theabsoluteAngle
.The fix simply introduces a new minimal interface
HasAngle
that bothPositionComponent
andBodyComponent
implement (PositionComponent
implements it automatically viaAngleProvider
), and reimplementsabsoluteAngle
so that it considers all ancestors with an angle and not just thePositionComponent
ones.Checklist
docs
and added dartdoc comments with///
.examples
ordocs
.Breaking Change?