Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for motion in cast_motion() before doing Bullet convexSweepTest(). #34219

Merged

Conversation

madmiraal
Copy link
Contributor

Addresses: #34210 (comment)

Also ensures that default closest_safe and closest_unsafe values are
defined both in cast_motion() and before cast_motion() is called in camera.cpp and physics_server.cpp.

Note: The other use of cast_motion() (in spring_arm.cpp) defines default values for the variables used for closest_safe and closest_unsafe:

real_t motion_delta(1);
real_t motion_delta_unsafe(1);

before calling cast_motion():
get_world()->get_direct_space_state()->cast_motion(shape->get_rid(), get_global_transform(), motion, 0, motion_delta, motion_delta_unsafe, excluded_objects, mask);

@madmiraal madmiraal force-pushed the check-motion-before-bullet-sweep branch from 2159d65 to ccfdae0 Compare December 16, 2019 16:16
@akien-mga
Copy link
Member

Ping @AndreaCatania

@madmiraal madmiraal force-pushed the check-motion-before-bullet-sweep branch 2 times, most recently from 8f6cbe2 to 1bbe7c1 Compare January 16, 2020 09:47
@akien-mga
Copy link
Member

akien-mga commented Jan 23, 2020

Does cast_motion in servers/physics/space_sw.cpp also need changes? (Beyond fixing its wrongly prefixed p_closest_safe and p_closest_unsafe which should start with r_ instead.)

@akien-mga akien-mga modified the milestones: 3.2, 4.0 Jan 23, 2020
@akien-mga akien-mga added the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Jan 23, 2020
@madmiraal
Copy link
Contributor Author

Does cast_motion in servers/physics/space_sw.cpp also need changes?

The short answer is yes, and it should be the same as whatever we decided here.

The long answer is that the problem lies with the gjk_epa_calculate_distance() function, which discards the sResults::Penetrating status set by the GjkEpa2::Distance() function, when it returns false:

results.status = gjk_status==GJK::eStatus::Inside?
sResults::Penetrating :
sResults::GJK_Failed ;
return(false);

bool gjk_epa_calculate_distance(const ShapeSW *p_shape_A, const Transform &p_transform_A, const ShapeSW *p_shape_B, const Transform &p_transform_B, Vector3 &r_result_A, Vector3 &r_result_B) {
GjkEpa2::sResults res;
if (GjkEpa2::Distance(p_shape_A, p_transform_A, p_shape_B, p_transform_B, p_transform_B.origin - p_transform_A.origin, res)) {
r_result_A = res.witnesses[0];
r_result_B = res.witnesses[1];
return true;
}
return false;
}

Therefore, instead of returning a negative distance or even zero, it sends a signal that it is unable to calculate the distance.

This false cascades back to PhysicsDirectSpaceStateSW::cast_motion(), which in turn returns false without setting values for p_closest_safe and p_closest_unsafe:

if (!CollisionSolverSW::solve_distance(shape, p_xform, col_obj->get_shape(shape_idx), col_obj_xform, point_A, point_B, aabb, &sep_axis)) {
return false;
}

@madmiraal madmiraal force-pushed the check-motion-before-bullet-sweep branch from 1bbe7c1 to 3ab4b62 Compare April 1, 2020 15:55
@madmiraal
Copy link
Contributor Author

Rebased following multiple changes to master. Since this is no longer cherry-pickable. I'll create a separate pull request with the original changes against the 3.2 branch.

@Calinou Calinou removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Apr 1, 2020
Copy link
Contributor

@AndreaCatania AndreaCatania left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems ok to be merged, Thanks!!

Also ensure that default closest_safe and closest_unsafe values are
defined in cast_motion() and before cast_motion() is called.
@madmiraal madmiraal force-pushed the check-motion-before-bullet-sweep branch from 3ab4b62 to 8ffe905 Compare June 21, 2020 15:29
@akien-mga akien-mga merged commit 858af3d into godotengine:master Jun 21, 2020
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants