flame-engine / flame

A Flutter based game engine.
https://flame-engine.org
MIT License
8.97k stars 878 forks source link

Fix issue after overlap #3207

Closed DavidChZh closed 1 day ago

DavidChZh commented 1 week ago

What happened?

As you can see in the video, after the objects in the game overlapped, they kept trying to repair it, but they were unable to do so, causing the objects to keep moving.

https://github.com/flame-engine/flame/assets/24714777/9ac2dcba-40cc-4792-955e-8e886a38db05

What do you expect?

When overlap is unavoidable and self-repair is not possible, is there a way to detect it and allow the developer to try to fix it with some code?

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?

No response

Relevant log output

No response

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

[✓] Flutter (Channel stable, 3.22.0, on macOS 14.3.1 23D60 darwin-arm64, locale zh-Hans-CN) • Flutter version 3.22.0 on channel stable at /Users/evdo/Desktop/development/flutter_sdk • Upstream repository https://github.com/flutter/flutter.git • Framework revision 5dcb86f68f (7 weeks ago), 2024-05-09 07:39:20 -0500 • Engine revision f6344b75dc • Dart version 3.4.0 • DevTools version 2.34.3 • Pub download mirror https://pub.flutter-io.cn • Flutter download mirror https://storage.flutter-io.cn

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/evdo/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231) • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15C65 • CocoaPods version 1.15.2

[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

[✓] VS Code (version 1.90.0) • VS Code at /Users/evdo/Desktop/Visual Studio Code.app/Contents • Flutter extension version 3.90.0

[✓] Connected device (6 available) • 2308CPXD0C (mobile) • 86aa5c5b • android-arm64 • Android 14 (API 34) • sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 • Android 14 (API 34) (emulator) • iPhone14 (mobile) • 00008110-001A64CE2E40A01E • ios • iOS 17.5.1 21F90 • macOS (desktop) • macos • darwin-arm64 • macOS 14.3.1 23D60 darwin-arm64 • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 14.3.1 23D60 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 126.0.6478.115

[✓] Network resources • All expected network resources are available.

• No issues found!

Affected platforms

Android

Other information

flame: 1.17.0 flame_forge2d: 0.18.0

Are you interested in working on a PR for this?

ufrshubham commented 6 days ago

Something similar was discussed in #3136

DavidChZh commented 6 days ago

Something similar was discussed in #3136

Sorry, I asked both questions. The main reason is that I think the two questions are different. 3136 is the continuous jitter caused by excessive gravity setting when there is no overlap. The current problem is the self-repair problem of the physics engine after the overlap occurs. When the gravity setting is too large, the 3136 problem is inevitable. The current problem is sporadic, and may occur once or several times per game. I compared the same WeChat mini-program game that has been launched. Based on the cocos engine, this problem also occurs, and the frequency is not much different from mine at present, but after the problem occurs, its self-repair is a very smooth process. Even in most cases, no self-repair is performed. Allowing overlapping objects to exist, because this situation often occurs when there are many graphics. In this case, not performing self-repair or a smooth repair is not conspicuous to users.

spydon commented 4 days ago

@DavidChZh are you allowing the bodies to sleep?

DavidChZh commented 4 days ago

@DavidChZh are you allowing the bodies to sleep? Allowed

DavidChZh commented 1 day ago

By reducing the gravity sensitivity, the frequency of this problem is greatly reduced. In the case of many rigid bodies and fixtures, the influence of gravity is too important.