82 lines
No EOL
2.2 KiB
Rust
82 lines
No EOL
2.2 KiB
Rust
/*
|
|
Trouble in Terror Town: Community Edition
|
|
Copyright (C) 2024 Mikolaj Wojciech Gorski
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
use bevy::prelude::*;
|
|
use bevy_xpbd_3d::prelude::*;
|
|
|
|
pub struct CharacterControllerPlugin;
|
|
|
|
impl Plugin for CharacterControllerPlugin{
|
|
fn build(&self, app: &mut App) {
|
|
app.add_systems(Update, update_grounded);
|
|
}
|
|
}
|
|
|
|
#[derive(Component)]
|
|
#[component(storage = "SparseSet")]
|
|
pub struct Grounded;
|
|
|
|
#[derive(Component)]
|
|
pub struct CharacterController{
|
|
pub walk_speed: f32,
|
|
}
|
|
|
|
impl Default for CharacterController {
|
|
fn default() -> Self {
|
|
CharacterController{
|
|
walk_speed: 4.0,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Bundle)]
|
|
pub struct CharacterControllerBundle{
|
|
character_controller: CharacterController,
|
|
rigid_body: RigidBody,
|
|
collider: Collider,
|
|
locked_axis: LockedAxes,
|
|
}
|
|
|
|
impl CharacterControllerBundle {
|
|
pub fn new(controller_collider: Collider, controller: CharacterController) -> Self {
|
|
Self{
|
|
character_controller: controller,
|
|
rigid_body: RigidBody::Dynamic,
|
|
collider: controller_collider,
|
|
locked_axis: LockedAxes::ROTATION_LOCKED,
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Default for CharacterControllerBundle {
|
|
fn default() -> Self {
|
|
CharacterControllerBundle{
|
|
character_controller: CharacterController::default(),
|
|
rigid_body: RigidBody::Dynamic,
|
|
collider: Collider::capsule(1.0, 0.5),
|
|
locked_axis: LockedAxes::ROTATION_LOCKED,
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn update_grounded(mut character_controller_query: Query<&CharacterController>){
|
|
|
|
for character_controller in character_controller_query.iter_mut() {
|
|
|
|
}
|
|
} |