Skip to content

Commit 6ae9101

Browse files
authored
Allow grounded distance to be user-configurable (#47)
Thanks!
1 parent 16778a9 commit 6ae9101

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/controller.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ pub struct FpsController {
8383
pub move_mode: MoveMode,
8484
pub radius: f32,
8585
pub gravity: f32,
86+
// If the distance to the ground is less than this value, the player is considered grounded
87+
pub grounded_distance: f32,
8688
pub walk_speed: f32,
8789
pub run_speed: f32,
8890
pub forward_speed: f32,
@@ -129,6 +131,7 @@ impl Default for FpsController {
129131
fn default() -> Self {
130132
Self {
131133
move_mode: MoveMode::Ground,
134+
grounded_distance: 0.125,
132135
radius: 0.5,
133136
fly_speed: 10.0,
134137
fast_fly_speed: 30.0,
@@ -183,9 +186,6 @@ impl Default for FpsController {
183186
// Used as padding by camera pitching (up/down) to avoid spooky math problems
184187
const ANGLE_EPSILON: f32 = 0.001953125;
185188

186-
// If the distance to the ground is less than this value, the player is considered grounded
187-
const GROUNDED_DISTANCE: f32 = 0.125;
188-
189189
const SLIGHT_SCALE_DOWN: f32 = 0.9375;
190190

191191
pub fn fps_controller_input(
@@ -286,7 +286,7 @@ pub fn fps_controller_move(
286286
// We do not want the shape cast to detect it,
287287
// so provide a slightly smaller collider in the XZ plane
288288
&scaled_collider_laterally(&collider, SLIGHT_SCALE_DOWN),
289-
ShapeCastOptions::with_max_time_of_impact(GROUNDED_DISTANCE),
289+
ShapeCastOptions::with_max_time_of_impact(controller.grounded_distance),
290290
filter,
291291
);
292292

0 commit comments

Comments
 (0)