From 83baecdff01894df55171ace7aa9e50b3001cc73 Mon Sep 17 00:00:00 2001 From: PouleyKetchoupp Date: Mon, 30 Aug 2021 11:48:43 -0700 Subject: Add AnimatableBody inherited from StaticBody for moving platforms Instead of having a physics node named Static that can be either Static or Kinematic, AnimatableBody is added again as a separate node: -Inherited from StaticBody to make its usage clearer -Still separated from CharacterBody to make its usage more focused Properly implemented constant velocity for kinematic bodies in godot physics servers (induced velocity without actually moving). Also updated description for the different physics nodes to make their usage clearer. --- servers/physics_2d/body_2d_sw.cpp | 8 ++++---- servers/physics_2d/body_2d_sw.h | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'servers/physics_2d') diff --git a/servers/physics_2d/body_2d_sw.cpp b/servers/physics_2d/body_2d_sw.cpp index 64f71fd25c..d86943e658 100644 --- a/servers/physics_2d/body_2d_sw.cpp +++ b/servers/physics_2d/body_2d_sw.cpp @@ -269,11 +269,13 @@ void Body2DSW::set_state(PhysicsServer2D::BodyState p_state, const Variant &p_va } break; case PhysicsServer2D::BODY_STATE_LINEAR_VELOCITY: { linear_velocity = p_variant; + constant_linear_velocity = linear_velocity; wakeup(); } break; case PhysicsServer2D::BODY_STATE_ANGULAR_VELOCITY: { angular_velocity = p_variant; + constant_angular_velocity = angular_velocity; wakeup(); } break; @@ -429,10 +431,10 @@ void Body2DSW::integrate_forces(real_t p_step) { if (mode == PhysicsServer2D::BODY_MODE_KINEMATIC) { //compute motion, angular and etc. velocities from prev transform motion = new_transform.get_origin() - get_transform().get_origin(); - linear_velocity = motion / p_step; + linear_velocity = constant_linear_velocity + motion / p_step; real_t rot = new_transform.get_rotation() - get_transform().get_rotation(); - angular_velocity = remainder(rot, 2.0 * Math_PI) / p_step; + angular_velocity = constant_angular_velocity + remainder(rot, 2.0 * Math_PI) / p_step; do_motion = true; @@ -621,8 +623,6 @@ Body2DSW::Body2DSW() : direct_state_query_list(this) { mode = PhysicsServer2D::BODY_MODE_DYNAMIC; active = true; - angular_velocity = 0; - biased_angular_velocity = 0; mass = 1; inertia = 0; user_inertia = false; diff --git a/servers/physics_2d/body_2d_sw.h b/servers/physics_2d/body_2d_sw.h index 9cd53ceca1..b83afdbec6 100644 --- a/servers/physics_2d/body_2d_sw.h +++ b/servers/physics_2d/body_2d_sw.h @@ -44,10 +44,13 @@ class Body2DSW : public CollisionObject2DSW { PhysicsServer2D::BodyMode mode; Vector2 biased_linear_velocity; - real_t biased_angular_velocity; + real_t biased_angular_velocity = 0.0; Vector2 linear_velocity; - real_t angular_velocity; + real_t angular_velocity = 0.0; + + Vector2 constant_linear_velocity; + real_t constant_angular_velocity = 0.0; real_t linear_damp; real_t angular_damp; -- cgit v1.2.3