-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
Cleared forces at end of body_2D integrate_forces #38648
Conversation
@madmiraal That's fine. That topic is still getting debated. This PR is merely here for when the verdict is decided. And the poster in that showed the lines of code in the files that he was referring too. |
I have been corrected. There is a difference between the 2D and 3D behaviour. However, I still think it's a bad idea, because, as discussed in my following comment, if we clear My inclination is to suggest changing the 3D version to not clear |
Clearing This change is correct. |
@sakar If the forces are cleared at the end of every step, Your example of a spaceship thruster is exactly why forces should not be cleared at the end of each step. The spaceship thruster is a continuous force that should only be changed when the player sends an input signal. Your code should be event driven. It's the physics engine, not your code, that should apply the force at every step. Gravity is the same. It's set once and the physics engine applies it at every step. |
@madmiraal The spaceship thruster demonstrates exactly why the current implementation is wrong. A thruster applies a continual force while it's on, applying some amount of force over time. The over time part is why you should be calling Clearing the applied forces each step is exactly how a number of other physics engines work, including Godot's own 3D physics implementation, Box2D, Bullet, PhysX, and Chipmunk. Changing the behavior of Godot's 3D physics to match the 2D physics would make it inconsistent with Bullet, creating confusion between the APIs. Also, changing 3D to match 2D would require additional methods to set and get the |
First, "everyone else does it this way" is not a good reason. Many bad ideas perpetuate because of this reasoning. Second, Godot is a game engine that uses physics not a physics engine. Therefore, the interface should make sense for making games not physics; regardless of whether or not it makes sense in a physics engine. Third, Finally, applying the changes to 3D would not be that much harder, except they would need to be made to both Godot and Bullet. An easier solution is not necessarily a better solution. The point is, whichever way we go, it's a breaking change; so now is the time to have the discussion to agree the best way forward. |
I wanted to bring up the spaceship thruster again because it demonstrates what I'm talking about regarding usage of the physics api. Let's say you have a little spaceship that continuously rotates at a constant rate. The player's only control is the spacebar, which when held causes the shapeship to accelerate in the direction it's facing. You might have a script like this:
Nice and simple. If Now with the current version where
Even if you handled the inputs in an event driven way thru |
@atinymelon If you want a one-off central force, you should use |
Having to modify A simple example is the same spaceship, but instead of a single thruster applying force to the center, it has two thrusters on its left and right ends. The controls are such that activating one thruster turns the ship, and activating both moves it forward. But implementing this behavior is a massive pain currently because the thrusters don't just apply force, they also apply some unknown amount of torque. |
Those that want to clear the forces at each iteration can do so by doing what this PR is suggesting i.e. by adding, to the beginning of their
There is no need to force this on every user. |
Yes, this works for individual objects, but if I want all or most of my rigidbodies to have this behavior, it doesn't quite work. Either:
The problem with 1 is that now I have to have more scripts running than I should, which can impact performance. Additionally, what happens if one of these rigidbodies has its script run AFTER a script that pushes it? Suddenly that force gets cleared before it has a chance to be integrated in the physics engine, so things don't work. We don't have precise control over when scripts run, so this can and will happen. In theory 2 may fix the script execution order problem if I can consistently have it run either before or after everything else, but it's also ridiculous that I'd have to do this.
This goes both ways. Aligning 3D physics with 2D like in #42850 would be forcing a change that introduces more burden for no real gain. It creates more work to produce the same behavior, and any theoretical benefit of a more 'event-based' approach is ultimately lost because most desired physics behavior has to be calculated each step anyways. Clearing 2D forces as this PR does is a change in behavior, yes, but it means these physics behaviors are much simpler because they require less boilerplate for the same thing. |
Cleared forces at end of body_2D integrate_forces for consistency with 3D version. Could not find where to fix in bullet implementation.
Fixes #38646