diff options
author | PouleyKetchoupp <pouleyketchoup@gmail.com> | 2021-12-07 18:09:54 -0700 |
---|---|---|
committer | PouleyKetchoupp <pouleyketchoup@gmail.com> | 2021-12-10 15:55:40 -0700 |
commit | 940f3fde5c5f902b6efd0f35fb6c7d23edd1da14 (patch) | |
tree | 1af330b010e4234cfe2694e94d25756c8e4e3734 /servers/physics_2d/godot_body_2d.cpp | |
parent | e69fa16eb3cd4cf4a591eb4c533b9eff45f79850 (diff) | |
download | redot-engine-940f3fde5c5f902b6efd0f35fb6c7d23edd1da14.tar.gz |
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.
Diffstat (limited to 'servers/physics_2d/godot_body_2d.cpp')
-rw-r--r-- | servers/physics_2d/godot_body_2d.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/servers/physics_2d/godot_body_2d.cpp b/servers/physics_2d/godot_body_2d.cpp index 44da5d4f3b..886fe4af0f 100644 --- a/servers/physics_2d/godot_body_2d.cpp +++ b/servers/physics_2d/godot_body_2d.cpp @@ -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 |