diff options
Diffstat (limited to 'servers')
-rw-r--r-- | servers/physics_2d/body_pair_2d_sw.cpp | 15 | ||||
-rw-r--r-- | servers/physics_2d/body_pair_2d_sw.h | 2 |
2 files changed, 15 insertions, 2 deletions
diff --git a/servers/physics_2d/body_pair_2d_sw.cpp b/servers/physics_2d/body_pair_2d_sw.cpp index 931125a1c0..669240b8da 100644 --- a/servers/physics_2d/body_pair_2d_sw.cpp +++ b/servers/physics_2d/body_pair_2d_sw.cpp @@ -375,6 +375,18 @@ bool BodyPair2DSW::setup(float p_step) { } #endif + + + c.bounce=MAX(A->get_bounce(),B->get_bounce()); + if (c.bounce) { + + Vector2 crA( -A->get_angular_velocity() * c.rA.y, A->get_angular_velocity() * c.rA.x ); + Vector2 crB( -B->get_angular_velocity() * c.rB.y, B->get_angular_velocity() * c.rB.x ); + Vector2 dv = B->get_linear_velocity() + crB - A->get_linear_velocity() - crA; + c.bounce = c.bounce * dv.dot(c.normal); + } + + } return true; @@ -420,8 +432,7 @@ void BodyPair2DSW::solve(float p_step) { A->apply_bias_impulse(c.rA,-jb); B->apply_bias_impulse(c.rB, jb); - real_t bounce=MAX(A->get_bounce(),B->get_bounce()); - real_t jn = -(bounce + vn)*c.mass_normal; + real_t jn = -(c.bounce + vn)*c.mass_normal; real_t jnOld = c.acc_normal_impulse; c.acc_normal_impulse = MAX(jnOld + jn, 0.0f); diff --git a/servers/physics_2d/body_pair_2d_sw.h b/servers/physics_2d/body_pair_2d_sw.h index ebe26776ed..15d7e62d3a 100644 --- a/servers/physics_2d/body_pair_2d_sw.h +++ b/servers/physics_2d/body_pair_2d_sw.h @@ -66,6 +66,8 @@ class BodyPair2DSW : public Constraint2DSW { bool active; Vector2 rA,rB; bool reused; + float bounce; + }; Vector2 offset_B; //use local A coordinates to avoid numerical issues on collision detection |