initiall commit + character controller groundwork
This commit is contained in:
commit
3dd0e2acf5
5 changed files with 4827 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
/target
|
||||||
4693
Cargo.lock
generated
Normal file
4693
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
11
Cargo.toml
Normal file
11
Cargo.toml
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
[package]
|
||||||
|
name = "silly_game"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
bevy = "0.13.0"
|
||||||
|
bevy_editor_pls = "0.8.1"
|
||||||
|
bevy_xpbd_3d = {git = "https://git.opencodebox.com/MikolajG/bevy_xpbd", branch = "reflect-serialize"}
|
||||||
65
src/charcacter_controller.rs
Normal file
65
src/charcacter_controller.rs
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
57
src/main.rs
Normal file
57
src/main.rs
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
//! A simple 3D scene with light shining over a cube sitting on a plane.
|
||||||
|
|
||||||
|
use bevy::prelude::*;
|
||||||
|
use bevy_xpbd_3d::prelude::*;
|
||||||
|
use bevy_editor_pls::prelude::*;
|
||||||
|
use charcacter_controller::*;
|
||||||
|
mod charcacter_controller;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
App::new()
|
||||||
|
.add_plugins((DefaultPlugins, PhysicsPlugins::default(), EditorPlugin::default(), CharacterControllerPlugin))
|
||||||
|
.add_systems(Startup, setup)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// set up a simple 3D scene
|
||||||
|
fn setup(
|
||||||
|
mut commands: Commands,
|
||||||
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
|
) {
|
||||||
|
// plane
|
||||||
|
commands.spawn((PbrBundle {
|
||||||
|
mesh: meshes.add(Plane3d::default().mesh().size(5.0, 5.0)),
|
||||||
|
material: materials.add(Color::WHITE),
|
||||||
|
transform: Transform::from_xyz(0., 0., 0.),
|
||||||
|
..default()
|
||||||
|
}, Collider::cuboid(5.0, 0.1, 5.0), RigidBody::Static));
|
||||||
|
// cube
|
||||||
|
// commands.spawn((RigidBody::Dynamic, PbrBundle {
|
||||||
|
// mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
|
||||||
|
// material: materials.add(Color::rgb_u8(124, 144, 255)),
|
||||||
|
// transform: Transform::from_xyz(0.0, 5.0, 0.0),
|
||||||
|
// ..default()
|
||||||
|
// }, Collider::cuboid(1.0, 1.0, 1.0)));
|
||||||
|
//player
|
||||||
|
commands.spawn((CharacterControllerBundle::new(Collider::capsule(1.0, 0.5), CharacterController::default()), PbrBundle{
|
||||||
|
mesh: meshes.add(Capsule3d::new(0.5, 1.0)),
|
||||||
|
material: materials.add(Color::rgb_u8(124, 144, 255)),
|
||||||
|
transform: Transform::from_xyz(0.0, 5.0, 0.0),
|
||||||
|
..default()
|
||||||
|
}));
|
||||||
|
// light
|
||||||
|
commands.spawn(PointLightBundle {
|
||||||
|
point_light: PointLight {
|
||||||
|
shadows_enabled: true,
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
transform: Transform::from_xyz(4.0, 8.0, 4.0),
|
||||||
|
..default()
|
||||||
|
});
|
||||||
|
// camera
|
||||||
|
commands.spawn(Camera3dBundle {
|
||||||
|
transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||||
|
..default()
|
||||||
|
});
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue