Improve RigidDynamicBody force and torque API

Makes the API for forces and impulses more flexible, easier to
understand and harmonized between 2D and 3D.

Rigid bodies now have 3 sets of methods for forces and impulses:
-apply_impulse() for impulses (one-shot and time independent)
-apply_force() for forces (time dependent) applied for the current step
-add_constant_force() for forces that keeps being applied each step

Also updated the documentation to clarify the different methods and
parameters in rigid body nodes, body direct state and physics servers.
This commit is contained in:
PouleyKetchoupp 2021-12-07 18:09:54 -07:00
parent e69fa16eb3
commit 940f3fde5c
28 changed files with 1082 additions and 395 deletions

View file

@ -569,9 +569,8 @@ void GodotBody2D::integrate_forces(real_t p_step) {
if (!omit_force_integration) {
//overridden by direct state query
Vector2 force = gravity * mass;
force += applied_force;
real_t torque = applied_torque;
Vector2 force = gravity * mass + applied_force + constant_force;
real_t torque = applied_torque + constant_torque;
real_t damp = 1.0 - p_step * total_linear_damp;
@ -598,7 +597,10 @@ void GodotBody2D::integrate_forces(real_t p_step) {
}
}
biased_angular_velocity = 0;
applied_force = Vector2();
applied_torque = 0.0;
biased_angular_velocity = 0.0;
biased_linear_velocity = Vector2();
if (do_motion) { //shapes temporarily extend for raycast