diff --git a/src/camera.rs b/src/camera.rs index 4ad8fff..b68b5c2 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -1,7 +1,7 @@ use avian3d::prelude::*; use bevy::prelude::*; -use crate::{controller::PlayerMovement, controls::Controls, physics_layers::GameLayer}; +use crate::{control::Controls, control::controller::PlayerMovement, physics_layers::GameLayer}; #[derive(Component, Reflect, Debug)] pub struct CameraTarget; diff --git a/src/control/collisions.rs b/src/control/collisions.rs new file mode 100644 index 0000000..6533900 --- /dev/null +++ b/src/control/collisions.rs @@ -0,0 +1,169 @@ +use avian3d::{math::*, prelude::*}; +use bevy::prelude::*; + +use super::controller::{CharacterController, MaxSlopeAngle}; + +/// Kinematic bodies do not get pushed by collisions by default, +/// so it needs to be done manually. +/// +/// This system handles collision response for kinematic character controllers +/// by pushing them along their contact normals by the current penetration depth, +/// and applying velocity corrections in order to snap to slopes, slide along walls, +/// and predict collisions using speculative contacts. +#[allow(clippy::type_complexity)] +pub fn kinematic_controller_collisions( + collisions: Res, + bodies: Query<&RigidBody>, + collider_parents: Query<&ColliderParent, Without>, + mut character_controllers: Query< + ( + &mut Position, + &Rotation, + &mut LinearVelocity, + Option<&MaxSlopeAngle>, + ), + (With, With), + >, + time: Res