summaryrefslogtreecommitdiffstats
path: root/servers/physics_3d/godot_body_3d.h
diff options
context:
space:
mode:
authorPouleyKetchoupp <pouleyketchoup@gmail.com>2021-11-25 08:26:38 -0700
committerPouleyKetchoupp <pouleyketchoup@gmail.com>2021-11-25 09:51:57 -0700
commit7032cf06378c81a16407cba78e5c50851cac60e8 (patch)
treeb6b697cbf36300aadcf3b9a621cddfa248645610 /servers/physics_3d/godot_body_3d.h
parentb3ec5a16ea3a9d8ae95b2d1686eb36f71c5f70f5 (diff)
downloadredot-engine-7032cf06378c81a16407cba78e5c50851cac60e8.tar.gz
Fix RigidDynamicBody gaining momentum with bounce
Bounce calculation now uses the previous frame's velocity, so it's consistent with the actual motion of the bodies involved and not the yet-to-be-applied forces. When bounce is 1, using the current velocity was causing the new forces (including gravity) to be taken into account, which lead to the bounce velocity to be higher than the falling velocity at the moment of impact, adding more and more energy over time.
Diffstat (limited to 'servers/physics_3d/godot_body_3d.h')
-rw-r--r--servers/physics_3d/godot_body_3d.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/servers/physics_3d/godot_body_3d.h b/servers/physics_3d/godot_body_3d.h
index bba9ec6c3a..6ea6d1fcaa 100644
--- a/servers/physics_3d/godot_body_3d.h
+++ b/servers/physics_3d/godot_body_3d.h
@@ -45,6 +45,9 @@ class GodotBody3D : public GodotCollisionObject3D {
Vector3 linear_velocity;
Vector3 angular_velocity;
+ Vector3 prev_linear_velocity;
+ Vector3 prev_angular_velocity;
+
Vector3 constant_linear_velocity;
Vector3 constant_angular_velocity;
@@ -207,6 +210,9 @@ public:
_FORCE_INLINE_ void set_angular_velocity(const Vector3 &p_velocity) { angular_velocity = p_velocity; }
_FORCE_INLINE_ Vector3 get_angular_velocity() const { return angular_velocity; }
+ _FORCE_INLINE_ Vector3 get_prev_linear_velocity() const { return prev_linear_velocity; }
+ _FORCE_INLINE_ Vector3 get_prev_angular_velocity() const { return prev_angular_velocity; }
+
_FORCE_INLINE_ const Vector3 &get_biased_linear_velocity() const { return biased_linear_velocity; }
_FORCE_INLINE_ const Vector3 &get_biased_angular_velocity() const { return biased_angular_velocity; }