diff options
| author | Pedro J. Estébanez | 2017-05-11 02:13:33 +0200 |
|---|---|---|
| committer | Pedro J. Estébanez | 2017-05-11 02:45:48 +0200 |
| commit | 5e4216fd497e8a4b1d4d0b0d204f2cb27f68f663 (patch) | |
| tree | fa170d57ab7ddd4a53eb68ef501234b34b3d39ec /servers | |
| parent | 8a7ff259cba78a4661f4749d49730fb4016ba453 (diff) | |
| download | godot-5e4216fd497e8a4b1d4d0b0d204f2cb27f68f663.tar.gz godot-5e4216fd497e8a4b1d4d0b0d204f2cb27f68f663.tar.zst godot-5e4216fd497e8a4b1d4d0b0d204f2cb27f68f663.zip | |
Fix one-way-collision detection
Also, change the explanation of the one-way collision direction in the docs to reflect how it is actually used by the engine and clear up the usage of the "max depth" property.
Diffstat (limited to 'servers')
| -rw-r--r-- | servers/physics_2d/space_2d_sw.cpp | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp index b1ff6d8ce..505b84a53 100644 --- a/servers/physics_2d/space_2d_sw.cpp +++ b/servers/physics_2d/space_2d_sw.cpp @@ -405,13 +405,10 @@ static void _rest_cbk_result(const Vector2 &p_point_A, const Vector2 &p_point_B, _RestCallbackData2D *rd = (_RestCallbackData2D *)p_userdata; if (rd->valid_dir != Vector2()) { - - if (rd->valid_dir != Vector2()) { - if (p_point_A.distance_squared_to(p_point_B) > rd->valid_depth * rd->valid_depth) - return; - if (rd->valid_dir.dot((p_point_A - p_point_B).normalized()) < Math_PI * 0.25) - return; - } + if (p_point_A.distance_squared_to(p_point_B) > rd->valid_depth * rd->valid_depth) + return; + if (rd->valid_dir.dot((p_point_A - p_point_B).normalized()) < Math_PI * 0.25) + return; } Vector2 contact_rel = p_point_B - p_point_A; @@ -744,7 +741,7 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Matrix32 &p_from, const cbk.amount = 0; cbk.ptr = cd; cbk.valid_dir = body->get_one_way_collision_direction(); - cbk.valid_depth = body->get_one_way_collision_max_depth(); + cbk.valid_depth = 10e20; //body is already unstuck; no need for depth testing at this stage Vector2 sep = mnormal; //important optimization for this to work fast enough bool collided = CollisionSolver2DSW::solve(body_shape, body_shape_xform, p_motion * (hi + contact_max_allowed_penetration), col_obj->get_shape(shape_idx), col_obj_xform, Vector2(), Physics2DServerSW::_shape_col_cbk, &cbk, &sep, 0); |
