Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
Ughuuu committed Oct 28, 2023
1 parent f55e20a commit 07eb697
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/rapier2d-wrapper/src/physics_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,12 @@ impl<'a> PhysicsHooks for PhysicsHooksCollisionFilter<'a> {

let collider_1 = &context.colliders[context.collider1];
let collider_2 = &context.colliders[context.collider2];
let body1 = &context.bodies[context.rigid_body1.unwrap()];
let rigidbody1_handle = context.rigid_body1.unwrap();
let body1 = context.bodies.get(rigidbody1_handle);
assert!(body1.is_some());
let body1 = body1.unwrap();
//body1.apply_impulse(vector![10.0, 0.0], true);
let body2 = &context.bodies[context.rigid_body2.unwrap()];

let mut filter_info = CollisionFilterInfo::new();
filter_info.user_data1 = UserData::new(collider_1.user_data);
filter_info.user_data2 = UserData::new(collider_2.user_data);
Expand Down
23 changes: 23 additions & 0 deletions src/servers/rapier_body_utils_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,29 @@ bool RapierBodyUtils2D::body_motion_recover(
Transform2D const &col_shape_transform = collision_body->get_transform() * collision_body->get_shape_transform(shape_index);
rapier2d::ShapeInfo col_shape_info = rapier2d::shape_info_from_body_shape(col_shape->get_rapier_shape(), col_shape_transform);


/*
if (body_shape->allows_one_way_collision() && col_obj->is_shape_set_as_one_way_collision(shape_idx)) {
cbk.valid_dir = col_obj_shape_xform.columns[1].normalized();
real_t owc_margin = col_obj->get_shape_one_way_collision_margin(shape_idx);
cbk.valid_depth = MAX(owc_margin, margin); //user specified, but never less than actual margin or it won't work
cbk.invalid_by_dir = 0;
if (col_obj->get_type() == GodotCollisionObject2D::TYPE_BODY) {
const GodotBody2D *b = static_cast<const GodotBody2D *>(col_obj);
if (b->get_mode() == PhysicsServer2D::BODY_MODE_KINEMATIC || b->get_mode() == PhysicsServer2D::BODY_MODE_RIGID) {
//fix for moving platforms (kinematic and dynamic), margin is increased by how much it moved in the given direction
Vector2 lv = b->get_linear_velocity();
//compute displacement from linear velocity
Vector2 motion = lv * last_step;
real_t motion_len = motion.length();
motion.normalize();
cbk.valid_depth += motion_len * MAX(motion.dot(-cbk.valid_dir), 0.0);
}
}
}*/

rapier2d::ContactResult contact = rapier2d::shapes_contact(p_space.get_handle(), body_shape_info, col_shape_info, p_margin);

if (!contact.collided) {
Expand Down
11 changes: 7 additions & 4 deletions src/spaces/rapier_space_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,14 @@ rapier2d::OneWayDirection RapierSpace2D::collision_modify_contacts_callback(rapi
if (collision_object_1->get_type() == RapierCollisionObject2D::TYPE_BODY && collision_object_2->get_type() == RapierCollisionObject2D::TYPE_BODY) {
RapierBody2D *body1 = static_cast<RapierBody2D *>(collision_object_1);
RapierBody2D *body2 = static_cast<RapierBody2D *>(collision_object_2);
//if (body1->is_static()) {
// TODO figure out when to set this.
//body2->set_linear_velocity(body2->get_linear_velocity() + body1->get_static_linear_velocity());
if (!body1->get_static_linear_velocity().is_zero_approx()) {
//body2->apply_central_impulse(body1->get_static_linear_velocity());
//body2->apply_central_impulse(Vector2(100,0));
}
if (!body2->get_static_linear_velocity().is_zero_approx()) {
//body1->apply_central_impulse(body2->get_static_linear_velocity());
}
//body2->set_angular_velocity(body2->get_angular_velocity() + body1->get_static_angular_velocity());
//}
//if (body2->is_static()) {
// TODO figure out when to set this.
//body1->set_linear_velocity(body1->get_linear_velocity() + body2->get_static_linear_velocity());
Expand Down

0 comments on commit 07eb697

Please sign in to comment.