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

Updated to latest library versions. #27

Merged
merged 4 commits into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ readme = "README.md"
description = "Bevy plugin that adds a Source engine inspired FPS movement controller"

[dependencies]
bevy = "0.11.3"
bevy_rapier3d = "0.22.0"
bevy = "0.12.1"
bevy_rapier3d = "0.23.0"

[[example]]
name = "minimal"
Expand Down
2 changes: 1 addition & 1 deletion examples/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ fn scene_colliders(
..default()
});
for node in &gltf.nodes {
let node = gltf_node_assets.get(&node).unwrap();
let node = gltf_node_assets.get(node).unwrap();
if let Some(gltf_mesh) = node.mesh.clone() {
let gltf_mesh = gltf_mesh_assets.get(&gltf_mesh).unwrap();
for mesh_primitive in &gltf_mesh.primitives {
Expand Down
20 changes: 16 additions & 4 deletions src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ pub fn fps_controller_move(
-Vec3::Y,
&cast_capsule,
0.125,
true,
filter,
);

Expand All @@ -270,8 +271,8 @@ pub fn fps_controller_move(
};
wish_speed = f32::min(wish_speed, max_speed);

if let Some((_, toi)) = ground_cast {
let has_traction = Vec3::dot(toi.normal1, Vec3::Y) > controller.traction_normal_cutoff;
if let Some((toi, toi_details)) = toi_details_unwrap(ground_cast) {
let has_traction = Vec3::dot(toi_details.normal1, Vec3::Y) > controller.traction_normal_cutoff;

// Only apply friction after at least one tick, allows b-hopping without losing speed
if controller.ground_tick >= 1 && has_traction {
Expand Down Expand Up @@ -304,7 +305,7 @@ pub fn fps_controller_move(

if has_traction {
let linvel = velocity.linvel;
velocity.linvel -= Vec3::dot(linvel, toi.normal1) * toi.normal1;
velocity.linvel -= Vec3::dot(linvel, toi_details.normal1) * toi_details.normal1;

if input.jump {
velocity.linvel.y = controller.jump_speed;
Expand Down Expand Up @@ -391,6 +392,15 @@ pub fn fps_controller_move(
}
}

fn toi_details_unwrap(ground_cast: Option<(Entity, Toi)>) -> Option<(Toi, ToiDetails)> {
if let Some((_, toi)) = ground_cast {
if let Some(details) = toi.details {
return Some((toi, details));
}
}
None
}

fn overhang_component(entity: Entity, transform: &Transform, physics_context: &RapierContext, velocity: Vec3, dt: f32) -> Option<Vec3> {
// Cast a segment (zero radius on capsule) from our next position back towards us
// If there is a ledge in front of us we will hit the edge of it
Expand All @@ -403,9 +413,11 @@ fn overhang_component(entity: Entity, transform: &Transform, physics_context: &R
-velocity,
&cast_capsule,
0.5,
true,
filter,
);
if let Some((_, toi)) = cast {
let toi_details = toi.details.unwrap();
let cast = physics_context.cast_ray(
future_position + Vec3::Y * 0.125, -Vec3::Y,
0.375,
Expand All @@ -414,7 +426,7 @@ fn overhang_component(entity: Entity, transform: &Transform, physics_context: &R
);
// Make sure that this is actually a ledge, e.g. there is no ground in front of us
if cast.is_none() {
let normal = -toi.normal1;
let normal = -toi_details.normal1;
let alignment = Vec3::dot(velocity, normal);
return Some(alignment * normal);
}
Expand Down