Skip to content

Commit

Permalink
Add crouching, update example, better sane defaults, minor fixes (#14)
Browse files Browse the repository at this point in the history
* Add feature to only apply friction if a certain slope angle is met, make systems sequential, make example have zero friction and restitution as we handle it ourselves

* Added crouching feature

* Modified crouching to be smoother

* Added a comment explaining crouching logic

* Set crouching to linear for now, add logic to prevent falling off ledge

* Bump version

---------

Co-authored-by: Aron Rüütli <[email protected]>
  • Loading branch information
qhdwight and Aron Rüütli authored Feb 15, 2023
1 parent 4f18e41 commit 022d469
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 64 deletions.
23 changes: 12 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_fps_controller"
version = "0.1.6-dev"
version = "0.1.7-dev"
edition = "2021"
authors = ["bevy_fps_controller"]
repository = "https://github.com/qhdwight/bevy_fps_controller"
Expand Down
74 changes: 51 additions & 23 deletions examples/minimal.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::f32::consts::TAU;

use bevy::prelude::*;
use bevy::window::CursorGrabMode;
use bevy::{
prelude::*,
window::CursorGrabMode,
};
use bevy_rapier3d::prelude::*;

use bevy_fps_controller::controller::*;
Expand All @@ -12,7 +14,7 @@ fn main() {
color: Color::WHITE,
brightness: 0.25,
})
.insert_resource(ClearColor(Color::rgb(0.752, 0.992, 0.984)))
.insert_resource(ClearColor(Color::hex("D4F5F5").unwrap()))
.insert_resource(RapierConfiguration::default())
.add_plugins(DefaultPlugins.set(WindowPlugin {
window: WindowDescriptor {
Expand Down Expand Up @@ -51,6 +53,14 @@ fn setup(
// where often time these two ideas are not exactly synced up
commands.spawn((
Collider::capsule(Vec3::Y * 0.5, Vec3::Y * 1.5, 0.5),
Friction {
coefficient: 0.0,
combine_rule: CoefficientCombineRule::Min,
},
Restitution {
coefficient: 0.0,
combine_rule: CoefficientCombineRule::Min,
},
ActiveEvents::COLLISION_EVENTS,
Velocity::zero(),
RigidBody::Dynamic,
Expand All @@ -73,9 +83,9 @@ fn setup(
RenderPlayer(0),
));

// World
commands.spawn_empty()
.insert(PbrBundle {
// Floor
commands.spawn((
PbrBundle {
mesh: meshes.add(Mesh::from(shape::Box {
min_x: -20.0,
max_x: 20.0,
Expand All @@ -85,18 +95,39 @@ fn setup(
max_z: 20.0,
})),
material: materials.add(StandardMaterial {
base_color: Color::hex("E6EED6").unwrap(),
base_color: Color::hex("8C9A9E").unwrap(),
..default()
}),
transform: Transform::IDENTITY,
transform: Transform::from_xyz(0.0, -0.25, 0.0),
..default()
})
.insert(Collider::cuboid(20.0, 0.25, 20.0))
.insert(RigidBody::Fixed)
.insert(Transform::IDENTITY);
},
Collider::cuboid(20.0, 0.25, 20.0),
RigidBody::Fixed,
));

commands.spawn_empty()
.insert(PbrBundle {
let material = materials.add(StandardMaterial {
base_color: Color::hex("747578").unwrap(),
..default()
});
commands.spawn((
PbrBundle {
mesh: meshes.add(Mesh::from(shape::Box {
min_x: -1.0,
max_x: 1.0,
min_y: -0.5,
max_y: 0.5,
min_z: -1.0,
max_z: 1.0,
})),
material: material.clone(),
transform: Transform::from_xyz(4.0, 0.5, 4.0),
..default()
},
Collider::cuboid(1.0, 1.0, 1.0),
RigidBody::Fixed,
));
commands.spawn((
PbrBundle {
mesh: meshes.add(Mesh::from(shape::Box {
min_x: -1.0,
max_x: 1.0,
Expand All @@ -105,16 +136,13 @@ fn setup(
min_z: -1.0,
max_z: 1.0,
})),
material: materials.add(StandardMaterial {
base_color: Color::hex("DDE2C6").unwrap(),
..default()
}),
transform: Transform::IDENTITY,
material: material.clone(),
transform: Transform::from_xyz(2.0, 1.0, 4.0),
..default()
})
.insert(Collider::cuboid(1.0, 1.0, 1.0))
.insert(RigidBody::Fixed)
.insert(Transform::from_xyz(4.0, 1.0, 4.0));
},
Collider::cuboid(1.0, 2.0, 1.0),
RigidBody::Fixed,
));
}

pub fn manage_cursor(
Expand Down
Loading

0 comments on commit 022d469

Please sign in to comment.