bevy_ichun/lib.rs
1//! # Kinematic Character Controller for Bevy and Avian3D
2//!
3//! Ichun provides a modular kinematic character controller (KCC) implementation
4//! for the Bevy engine using the Avian3D physics backend. It handles common gameplay
5//! features like character movement, jumping, running, and interaction with the environment.
6//!
7//! ## Features
8//!
9//! * Kinematic character controller with physics-based collision response
10//! * Modular design with separate movement and input systems
11//! * Support for slopes, moving platforms and static geometry
12//! * Configurable gravity, jump physics, and movement parameters
13//! * Optional input handling with customizable key bindings
14//!
15//! ## Module Structure
16//!
17//! * `kcc`: Core kinematic character controller functionality and physics
18//! * `movement_events`: Movement systems that generate actions to apply velocity from input
19//! * `input`: Input handling systems that generate movement events
20//! * `actions`: action systems execute movement actions to the character
21//! * `system_sets`: Bevy system sets for proper execution ordering
22//!
23//! ## Usage
24//!
25//! Add the plugin to your Bevy app:
26//!
27//! ```rust
28//! use bevy::prelude::*;
29//! use ichun::IchunPlugin;
30//!
31//! fn main() {
32//! App::new()
33//! .add_plugins(DefaultPlugins)
34//! .add_plugins(IchunPlugin)
35//! .run();
36//! }
37//! ```
38//!
39//! Then add the KCC components to your character entity:
40//!
41//! ```rust
42//! use bevy::prelude::*;
43//! use bevy_ichun::{IchunPlugin, input::KccInputConfig, kcc::Kcc, movement::KccMovementConfig};
44//!
45//! fn spawn_character(mut commands: Commands) {
46//! commands.spawn((
47//! Kcc::default(),
48//! KccMovementConfig::default(),
49//! KccInputConfig::default(),
50//! Mesh3d(meshes.add(Capsule3d::new(0.4, 1.0))),
51//! MeshMaterial3d(matl.add(Color::srgb(0.8, 0.7, 0.6))),
52//! Transform::from_xyz(0.0, 3.0, 0.0),
53//! ));
54//! }
55//! ```
56use bevy::prelude::*;
57use kcc::IchunKccPlugin;
58
59#[cfg(feature = "kcc_movement_events")]
60use movement_events::IchunMovementEventsPlugin;
61
62#[cfg(feature = "kcc_input")]
63use input::IchunInputPlugin;
64use system_sets::IchunSystemSetsPlugin;
65
66#[cfg(feature = "kcc_actions")]
67use actions::IchunActionsPlugin;
68
69pub mod kcc;
70#[cfg(feature = "kcc_movement_events")]
71pub mod movement_events;
72pub mod system_sets;
73
74#[cfg(feature = "kcc_input")]
75pub mod input;
76
77#[cfg(feature = "kcc_actions")]
78pub mod actions;
79
80pub struct IchunPlugin;
81
82/// Main plugin for the Ichun character controller.
83///
84/// This plugin adds all necessary systems and components for the character controller
85/// to function. It automatically configures the proper system execution order and
86/// adds all required plugins.
87///
88/// # Features
89///
90/// The plugin's behavior can be configured using Cargo features:
91/// - `kcc_movement_events`: Enables the movement systems (enabled by default)
92/// - `kcc_input`: Enables input handling systems (enabled by default)
93///
94/// # Example
95///
96/// ```rust
97/// use bevy::prelude::*;
98/// use bevy_ichun::IchunPlugin;
99///
100/// fn main() {
101/// App::new()
102/// .add_plugins(DefaultPlugins)
103/// .add_plugins(IchunPlugin)
104/// .run();
105/// }
106/// ```
107impl Plugin for IchunPlugin {
108 fn build(&self, app: &mut bevy::app::App) {
109 app.add_plugins((
110 IchunSystemSetsPlugin,
111 IchunKccPlugin,
112 #[cfg(feature = "kcc_movement_events")]
113 IchunMovementEventsPlugin,
114 #[cfg(feature = "kcc_input")]
115 IchunInputPlugin,
116 #[cfg(feature = "kcc_actions")]
117 IchunActionsPlugin,
118 ));
119 }
120}