`CameraComponent.follow` follows the local position of a nested target
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
Issue này chưa được đánh giá.
Mô tả
What happened?
FollowBehavior moves its owner towards target.position (follow_behavior.dart#L55-L58), which is the target's position relative to its parent. When the target is a child of another PositionComponent, that isn't where the target is in the world, so CameraComponent.follow points the camera at the wrong place.
For example, with a knight that is a child of a moving platform and stands at (32, 30) on it, the camera looks at (32, 30) in the world, wherever the platform is. As the platform moves, the camera stays where it is and the knight leaves the screen. follow(target, snap: true) has the same problem, since it sets the viewfinder's position to target.position too (camera_component.dart#L389).
The same happens when a FollowBehavior is used between two components with different parents, e.g. a follower in one container following a target in another.
What do you expect?
The camera follows the target wherever it is in the component tree, as it does for a direct child of the world.
How can we reproduce this?
- Add a
PositionComponent(the platform) to the world, and move it. - Add the component to follow as a child of the platform.
- Call
camera.follow(knight). The camera follows the knight's position on the platform, not its position in the world.
What steps should take to fix this?
FollowBehavior will convert the target's position into the coordinate system of the owner's position when the target is a PositionComponent with another parent than the owner: into world coordinates through absolutePosition for an owner that isn't a PositionComponent, such as the camera's Viewfinder, and through absoluteToLocal and positionOf for a PositionComponent owner. When the target and the owner have the same parent, target.position is used as before. CameraComponent.follow will use the same position for snap.
Targets that aren't PositionComponents, such as a PositionProviderImpl, are followed at their position as given, as before. Until the fix is released, a nested target can be followed with camera.follow(PositionProviderImpl(getValue: () => knight.absolutePosition)).
Do have an example of where the bug occurs?
import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flame/palette.dart';
import 'package:flutter/widgets.dart';
void main() => runApp(GameWidget(game: ReproGame()));
class ReproGame extends FlameGame {
@override
Future<void> onLoad() async {
world.add(RectangleComponent(size: Vector2.all(2000)));
final platform = MovingPlatform(position: Vector2(100, 100));
final knight = RectangleComponent(
position: Vector2(32, 30),
size: Vector2(16, 28),
anchor: Anchor.bottomCenter,
paint: BasicPalette.red.paint(),
);
world.add(platform..add(knight));
camera.follow(knight, snap: true);
}
}
class MovingPlatform extends RectangleComponent {
MovingPlatform({super.position})
: super(size: Vector2(64, 40), anchor: Anchor.center);
@override
void update(double dt) {
position.x += 100 * dt;
}
}
https://github.com/user-attachments/assets/eb723755-e2dc-4399-aaae-994319cf2c19
Expected: the red knight stays at the center of the screen while the platform carries it. Actual: the camera stays at (32, 30) and the knight moves off the screen.
Relevant log output
Nothing is logged or thrown.
Execute in a terminal and put output into the code block below
[√] Flutter (Channel stable, 3.50.0, on Microsoft Windows [Version 10.0.22631.6199], locale en-US)
• Flutter version 3.50.0 on channel stable
• Framework revision ab2912035e (10 days ago), 2026-11-09 08:50:21 -0800
• Engine revision 371f77202a
• Dart version 3.14.0
• DevTools version 2.61.0
[√] Windows Version (11 Pro 64-bit, 23H2, 2009)
[√] Android toolchain - develop for Android devices (Android SDK version 36.1.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2026 18.11.2)
[√] Connected device (3 available)
[√] Network resources
• No issues found!
Affected platforms
All
Other information
No response
Are you interested in working on a PR for this?
- I want to work on this
- Ngôn ngữ chính
- Dart
- Star
- 10.8k
- Fork
- 1.1k
- Merge trung bình
- 2 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 61
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của flame-engine/flame
-
Timer with tickCount stays finished after start() or reset()Có thể đã có người làm @matthewalberto đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
flame-engine/flame#4240 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`ComponentPool` returns components to the pool while they are still in use, and loses components removed before mountingCó thể đã có người làm @ufrshubham đã nhận 18 ngày trước. Đang mởbug
flame-engine/flame#4191 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Move the flame_studio debugging features to flame_devtoolsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởenhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
flame-engine/flame#4176 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
discussion enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
flame-engine/flame#4175 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
flame-engine/flame#4174 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của flame-engine/flame
Issue tương tự
-
[feat]: 截图挑选时希望能双击缩略图直接选中/取消Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[体验问题] 新建下载任务时重命名会丢失原文件后缀Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
spotiflacapp/SpotiFLAC-Mobile#935 ·
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
chriskelly/wish-together#193 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: player feature request
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100