1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
//! # Character Actions System
//!
//! This module provides a component-based action system for handling character movement,
//! rotation, jumping, and gravity modifications. It processes actions in a specific order
//! and automatically clears them after each frame to ensure consistent behavior.
//!
//! ## Components
//!
//! * [`KccActions`]: Container component that holds all possible actions for an entity
//!
//! ## Usage
//!
//! ```rust
//! use bevy::prelude::*;
//! use your_crate::actions::{KccActions, MoveAction, JumpAction};
//!
//! fn setup_character(mut commands: Commands) {
//! commands.spawn((
//! Kcc,
//! KccActions::new(),
//! ));
//! }
//! ```
use *;
use GravityAction;
use JumpAction;
use MoveAction;
use RotateAction;
use crate::;
/// Plugin that manages the character actions system.
///
/// This plugin adds systems for processing and clearing character actions.
/// Actions are processed during the Update schedule and cleared during PostUpdate
/// to ensure they only affect the character for one frame.
///
/// ## Systems Added
///
/// * `process_kcc_actions_sys` - Processes all active actions on entities (Update)
/// * `clear_kcc_actions_sys` - Clears all actions after processing (PostUpdate)
;
/// Component that holds all possible actions for a kinematic character controller.
///
/// This component acts as a container for different types of actions that can be
/// applied to a character. Actions are processed in a specific order each frame:
/// 1. Rotation actions (camera/character rotation)
/// 2. Movement actions (velocity changes)
/// 3. Jump actions (vertical impulses)
/// 4. Gravity actions (gravity modifications)
///
/// Actions are automatically cleared after each frame to prevent unintended
/// carry-over effects.
///
/// ## Example
///
/// ```rust
/// use bevy::prelude::*;
/// use your_crate::actions::{KccActions, JumpAction};
///
/// // System that handles jump input and creates jump actions
/// fn handle_jump_input(
/// keys: Res<ButtonInput<KeyCode>>,
/// mut query: Query<&mut KccActions, With<Player>>,
/// ) {
/// if keys.just_pressed(KeyCode::Space) {
/// for mut actions in query.iter_mut() {
/// // Create a jump action when space is pressed
/// actions.jump_action = Some(JumpAction::new(500.0)
/// .with_allow_in_air(false));
/// }
/// }
/// }
/// ```
/// System that processes all active actions on entities with `KccActions` components.
///
/// This system runs during the Update schedule and processes actions in a specific order:
/// 1. **Rotation Actions**: Applied to the entity's Transform for camera/character rotation
/// 2. **Movement Actions**: Applied to KccVelocity for movement and acceleration
/// 3. **Jump Actions**: Applied to KccVelocity for vertical impulses and jumping
/// 4. **Gravity Actions**: Applied to KccVelocity for gravity modifications
///
/// The processing order ensures that rotations are applied before movement calculations,
/// and that gravity modifications are applied last to override any conflicting effects.
///
/// ## Required Components
///
/// Entities processed by this system must have:
/// * `KccActions` - The actions to process
/// * `KccVelocity` - For velocity modifications
/// * `Transform` - For rotation modifications
/// * `Kcc` - For character controller state
/// System that clears all actions after they have been processed.
///
/// This system runs during the PostUpdate schedule to ensure that all actions
/// are reset to `None` after being processed. This prevents actions from
/// carrying over to the next frame and ensures consistent, predictable behavior.
///
/// Without this clearing step, actions would continue to be applied every frame
/// until manually removed, leading to uncontrolled movement or rotation.