-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
RigidBody2D does not clear forces at end of integration, RigidBody does #38646
Comments
In the attached reproduction project, nothing happens when I run the 2D scene. I'm not sure which behavior is desired, but in addition to an inconsistency between 2D and 3D, this is inconsistent between Bullet and Godot physics in 3D. |
@aaronfranke sorry, you move one of the nodes (Player) with wasd and the other (Magnet) has a force applied to it to follow if it is certain distance away from Player. Same with the 3D scene. If you replace the apply_central_impulse call in the Magnet script with add_central_force, Magnet flies off the screen because the forces are accumulating on top of the forces from the previous frames. My opinion is that the behavior should be consistent within Godot, whether it's 2D or 3D, or to make it configurable with the same defaults. Also fwiw I think clearing forces at the end of integration is probably the most intuitive for common use case. |
|
Regarding the difference between Godot and Bullet physics 3D: The issue is to do with the |
In 3D the applied_force is cleared at the end of integration. The equivalent line of code is not there for 2D, unless I'm missing something. In both 2D and 3D, the damping values only seem to decrease velocity over time (3D, 2D), not applied_force, unless again I'm missing something? In the phrase "constant directional force" I take constant to mean that the magnitude of the force is constant, not that it will be applied persistently. Fwiw analogous calls in other frameworks don't exhibit this behavior by default, so it feels like a reasonable assumption it wouldn't here too, especially since it doesn't in 3D RigidBodies.
I'll upload another test project today. |
You're right. I had not noticed that before.
The question then is, what is the difference between
I've created the following minimal project to demonstrate the difference: Both implement the following functions (except under 2D the vector is
Under 2D using |
The issue I see is that in the 2D physics Another way to look at it is that This is how other physics engines like Box2D handle this, and how Godot's 3D physics handles this, so I believe the issue is Godot's 2D physics not clearing |
The docs could probably also use another sentence or two on |
@name-here Better, you could contribute to the class reference directly 🙂 |
I have different question which my clear/help with this discussion. If I always done it in the past as follows (and it worked)
Also there are ambiguities/inconsistencies in docs between |
Godot version:
3.2.1
OS/device including version:
Windows 10
Issue description:
RigidBody2D does not appear to clear accumulated forces at the end of integration in the same way RigidBody appears to do.
This results in calls to add_force in scripts to accumulate forces over multiple physics steps, which I feel might be unintuitive for new users since:
Not actually sure if this is a bug or if it's intended this way. If it was intended, it would be good to document it.
Steps to reproduce:
Call add_force on any RigidBody2D in a script in _physics_process.
Minimal reproduction project:
PhysicsTest.zip
The text was updated successfully, but these errors were encountered: