Created
January 6, 2023 22:03
-
-
Save XMPPwocky/56623c451e1ffdf5aa9e177e8204e2ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use rapier3d::na; | |
use rapier3d::parry; | |
use rapier3d::prelude::*; | |
fn main() { | |
let mut rigid_body_set = RigidBodySet::new(); | |
let mut collider_set = ColliderSet::new(); | |
let start_pos = na::Isometry3::from(na::Translation3::new(-6.008857, -315.2329, -175.45639)); | |
let player_shape = ColliderBuilder::capsule_y(0.5, 0.5) | |
.active_collision_types(ActiveCollisionTypes::all()) | |
.build(); | |
let move_dir = na::Vector3::new(0.047952335, -0.85927814, -0.509256); | |
let move_dist = 0.95040697; | |
let rb_pos = na::Isometry3 { | |
translation: na::Translation3::new(0.0, -58.8, -14.9), | |
rotation: na::UnitQuaternion::from_quaternion(na::Quaternion::new( | |
-0.43301365, | |
0.25000057, | |
0.43301252, | |
0.74999934, | |
)), | |
}; | |
let rigid_body = RigidBodyBuilder::fixed().position(rb_pos).build(); | |
let rigid_body_h = rigid_body_set.insert(rigid_body); | |
let collider = ColliderBuilder::cuboid(10.0, 10.0, 1999.9998) | |
.active_collision_types(ActiveCollisionTypes::all()) | |
.build(); | |
let collider_h = collider_set.insert_with_parent(collider, rigid_body_h, &mut rigid_body_set); | |
let island_manager = IslandManager::new(); | |
let mut query_pipeline = QueryPipeline::new(); | |
rigid_body_set.propagate_modified_body_positions_to_colliders(&mut collider_set); | |
query_pipeline.update(&island_manager, &rigid_body_set, &collider_set); | |
let qp = query_pipeline.cast_shape( | |
&rigid_body_set, | |
&collider_set, | |
&start_pos, | |
&move_dir, | |
player_shape.shape(), | |
move_dist, | |
true, | |
QueryFilter::new(), | |
); | |
println!("cast result: {:?}", qp); | |
let collider = collider_set.get(collider_h).unwrap(); | |
let mut end_pos = start_pos; | |
end_pos.append_translation_mut(&na::Translation3::from(move_dir * move_dist)); | |
let contact = parry::query::contact( | |
&rb_pos, | |
collider.shape(), | |
&end_pos.into(), | |
player_shape.shape(), | |
0.0, | |
) | |
.unwrap(); | |
println!("{:?}", contact); | |
if let Some(contact) = contact { | |
assert!(contact.dist >= 0.0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment