i have not the slightest idea why this is blowing up in my face rn

This commit is contained in:
Schrottkatze 2025-06-27 22:43:43 +02:00
parent 324f1c04ed
commit 8f6e24875a
Signed by: schrottkatze
SSH key fingerprint: SHA256:/raZeWZ2RLThYkX/nq26frnmA4Bi3qRM/hijRmDBa10
12 changed files with 210 additions and 88 deletions

Binary file not shown.

View file

@ -3,50 +3,72 @@
"generator":"Khronos glTF Blender I/O v4.4.56", "generator":"Khronos glTF Blender I/O v4.4.56",
"version":"2.0" "version":"2.0"
}, },
"extensionsUsed":[
"KHR_lights_punctual"
],
"extensionsRequired":[
"KHR_lights_punctual"
],
"extensions":{
"KHR_lights_punctual":{
"lights":[
{
"color":[
1,
1,
1
],
"intensity":54351.41306588226,
"type":"point",
"name":"Light"
}
]
}
},
"scene":0, "scene":0,
"scenes":[ "scenes":[
{ {
"extras":{
"skein_extension_properties":{
"enabled":1
}
},
"name":"Scene", "name":"Scene",
"nodes":[ "nodes":[
0, 0,
1 1,
2,
3
] ]
} }
], ],
"nodes":[ "nodes":[
{ {
"extras":{ "extensions":{
"skein_two":[ "KHR_lights_punctual":{
{ "light":0
"name":"TPCTarget", }
"selected_type_path":"mgd2_demonic_posession::TPCTarget" },
"name":"Light",
"rotation":[
-0.28416627645492554,
0.7269423007965088,
0.34203392267227173,
0.5232754945755005
],
"translation":[
4.076245307922363,
5.903861999511719,
-1.0054539442062378
]
}, },
{ {
"name":"StaticColliderConfig", "extras":{
"selected_type_path":"mgd2_demonic_posession::game::scene::StaticColliderConfig",
"mgd2_demonic_posession::game::scene::StaticColliderConfig":{
"x":10.0,
"y":5.0,
"z":1.0
}
}
],
"active_component_index":1,
"skein":[ "skein":[
{
"mgd2_demonic_posession::TPCTarget":{}
},
{ {
"mgd2_demonic_posession::game::scene::StaticColliderConfig":{ "mgd2_demonic_posession::game::scene::StaticColliderConfig":{
"x":10.0, "x":10.0,
"y":5.0, "y":15.0,
"z":1.0 "z":1.0
} }
},
{
"bevy_rapier3d::dynamics::rigid_body::RigidBody":"Fixed"
} }
] ]
}, },
@ -55,18 +77,6 @@
}, },
{ {
"extras":{ "extras":{
"skein_two":[
{
"name":"StaticColliderConfig",
"selected_type_path":"mgd2_demonic_posession::game::scene::StaticColliderConfig",
"mgd2_demonic_posession::game::scene::StaticColliderConfig":{
"y":2.0,
"z":2.0,
"x":2.0
}
}
],
"active_component_index":0,
"skein":[ "skein":[
{ {
"mgd2_demonic_posession::game::scene::StaticColliderConfig":{ "mgd2_demonic_posession::game::scene::StaticColliderConfig":{
@ -88,7 +98,22 @@
"translation":[ "translation":[
0, 0,
1.5, 1.5,
0 3
]
},
{
"extras":{
"skein":[
{
"mgd2_demonic_posession::game::player::PlayerSpawnMarker":{}
}
]
},
"name":"Empty",
"translation":[
0,
3,
-4
] ]
} }
], ],
@ -128,12 +153,12 @@
"max":[ "max":[
5, 5,
0.5, 0.5,
2.5 7.5
], ],
"min":[ "min":[
-5, -5,
-0.5, -0.5,
-2.5 -7.5
], ],
"type":"VEC3" "type":"VEC3"
}, },

Binary file not shown.

View file

@ -6,5 +6,8 @@ use bevy::prelude::*;
/// Sets up the camera for the entire app, with a starting position for the game. (TODO: probably change that) /// Sets up the camera for the entire app, with a starting position for the game. (TODO: probably change that)
/// This camera is also used for menu rendering etc. /// This camera is also used for menu rendering etc.
pub fn setup(mut c: Commands) { pub fn setup(mut c: Commands) {
c.spawn(Camera3d::default()); c.spawn((
Camera3d::default(),
Transform::from_xyz(15., 10., 15.).looking_at(Vec3::ZERO, Vec3::Y),
));
} }

View file

@ -3,6 +3,8 @@ use std::path::PathBuf;
use bevy::prelude::*; use bevy::prelude::*;
use clap::Subcommand; use clap::Subcommand;
use crate::game::PlayerMode;
#[derive(Event, Debug, Subcommand, PartialEq, Eq)] #[derive(Event, Debug, Subcommand, PartialEq, Eq)]
pub enum DebugEvent { pub enum DebugEvent {
/// Close the debug console. /// Close the debug console.
@ -54,7 +56,7 @@ pub enum DebugEvent {
#[command(name = "enable-debug", aliases = ["debug-enable"])] #[command(name = "enable-debug", aliases = ["debug-enable"])]
EnableDebugMode, EnableDebugMode,
/// Load a gltf scene. /// Load a gltf scene. Requires debug mode.
/// ///
/// Auto-reloading isn't possible due to engine reasons, see: /// Auto-reloading isn't possible due to engine reasons, see:
/// https://github.com/bevyengine/bevy/pull/18358 /// https://github.com/bevyengine/bevy/pull/18358
@ -72,4 +74,7 @@ pub enum DebugEvent {
/// Toggles rapier debug mode /// Toggles rapier debug mode
#[command(aliases = ["rapier-debug", "rapier"])] #[command(aliases = ["rapier-debug", "rapier"])]
DebugRapier, DebugRapier,
/// Manually call player initialisation
InitPlayer { mode: PlayerMode },
} }

View file

@ -3,13 +3,15 @@ use bevy::prelude::*;
use crate::{ use crate::{
AppState, AppState,
cleanup::{self, despawn}, cleanup::{self, despawn},
debug::DebugMode,
}; };
mod camera; mod camera;
mod debug; mod debug;
mod player;
mod scene; mod scene;
pub use player::PlayerMode;
/// Gameplay system set. All functions in this control the gameplay (duh). /// Gameplay system set. All functions in this control the gameplay (duh).
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)] #[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
struct GameplaySet; struct GameplaySet;
@ -19,6 +21,7 @@ pub fn plugin(app: &mut App) {
OnExit(AppState::Ingame), OnExit(AppState::Ingame),
despawn::<cleanup::Scene>.in_set(GameplaySet), despawn::<cleanup::Scene>.in_set(GameplaySet),
) )
.add_plugins((camera::plugin, scene::plugin, debug::plugin)); .add_plugins((camera::plugin, scene::plugin, debug::plugin))
.add_plugins(player::plugin);
app.configure_sets(Update, GameplaySet.run_if(in_state(AppState::Ingame))); app.configure_sets(Update, GameplaySet.run_if(in_state(AppState::Ingame)));
} }

View file

@ -8,37 +8,37 @@ use crate::AppState;
use super::GameplaySet; use super::GameplaySet;
pub fn plugin(app: &mut App) { pub fn plugin(app: &mut App) {
app.add_plugins(ThirdPersonCameraPlugin) // app.add_plugins()
.add_systems( // .add_systems(
OnEnter(AppState::Ingame), // OnEnter(AppState::Ingame),
setup_game_camera.in_set(GameplaySet), // setup_game_camera.in_set(GameplaySet),
) // )
// .add_systems(Update, auto_target) // .add_systems(Update, auto_target)
.add_systems(OnExit(AppState::Ingame), remove_tpc.in_set(GameplaySet)); // .add_systems(OnExit(AppState::Ingame), remove_tpc.in_set(GameplaySet));
} }
/// Adds [ThirdPersonCamera] to our existing camera. /// Adds [ThirdPersonCamera] to our existing camera.
pub fn setup_game_camera(mut c: Commands, cam: Single<Entity, With<Camera3d>>) { // pub fn setup_game_camera(mut c: Commands, cam: Single<Entity, With<Camera3d>>) {
c.entity(*cam).insert(ThirdPersonCamera { // c.entity(*cam).insert(ThirdPersonCamera {
cursor_lock_key: KeyCode::Space, // cursor_lock_key: KeyCode::Space,
cursor_lock_toggle_enabled: true, // cursor_lock_toggle_enabled: true,
gamepad_settings: CustomGamepadSettings::default(), // gamepad_settings: CustomGamepadSettings::default(),
cursor_lock_active: true, // cursor_lock_active: true,
sensitivity: Vec2::new(1.0, 1.0), // sensitivity: Vec2::new(1.0, 1.0),
mouse_orbit_button_enabled: true, // mouse_orbit_button_enabled: true,
mouse_orbit_button: MouseButton::Middle, // mouse_orbit_button: MouseButton::Middle,
offset_enabled: false, // offset_enabled: false,
offset: Offset::new(0.5, 0.4), // offset: Offset::new(0.5, 0.4),
offset_toggle_enabled: false, // offset_toggle_enabled: false,
offset_toggle_speed: 5.0, // offset_toggle_speed: 5.0,
offset_toggle_key: KeyCode::KeyE, // offset_toggle_key: KeyCode::KeyE,
zoom_enabled: true, // zoom_enabled: true,
zoom: Zoom::new(1.5, 30.0), // zoom: Zoom::new(1.5, 30.0),
zoom_sensitivity: 1.0, // zoom_sensitivity: 1.0,
..Default::default() // ..Default::default()
}); // });
info!("Third person camera set up!") // info!("Third person camera set up!")
} // }
// fn auto_target( // fn auto_target(
// mut c: Commands, // mut c: Commands,

View file

@ -4,7 +4,7 @@ use bevy::{
asset::{AssetPath, io::AssetSourceEvent}, asset::{AssetPath, io::AssetSourceEvent},
prelude::*, prelude::*,
}; };
use bevy_rapier3d::render::DebugRenderContext; use bevy_rapier3d::{prelude::RigidBody, render::DebugRenderContext};
use crate::debug::{ConsoleLog, DebugEvent, DebugMode}; use crate::debug::{ConsoleLog, DebugEvent, DebugMode};
@ -37,7 +37,11 @@ fn handle_load_gltf(
let scene_handle = asset_server let scene_handle = asset_server
.load(GltfAssetLabel::Scene(0).from_asset(AssetPath::from(asset_path.clone()))); .load(GltfAssetLabel::Scene(0).from_asset(AssetPath::from(asset_path.clone())));
let mut scene = c.spawn((SceneRoot(scene_handle), HasPath(asset_path.clone()))); let mut scene = c.spawn((
SceneRoot(scene_handle),
HasPath(asset_path.clone()),
// RigidBody::Fixed,
));
if let Some(id) = id { if let Some(id) = id {
scene.insert(Id(id.clone())); scene.insert(Id(id.clone()));

84
src/game/player.rs Normal file
View file

@ -0,0 +1,84 @@
use bevy::prelude::*;
use bevy_rapier3d::{
prelude::*,
rapier::{
control::KinematicCharacterController,
prelude::{ColliderType, MassProperties},
},
};
use clap::ValueEnum;
use crate::{
AppState,
debug::{ConsoleLog, DebugEvent, DebugMode},
};
#[derive(States, Default, Debug, Clone, Copy, PartialEq, Eq, Hash, Reflect, ValueEnum)]
pub enum PlayerMode {
#[default]
Uninitialized,
Normal,
FreeCam,
}
pub fn plugin(app: &mut App) {
app.register_type::<PlayerSpawnMarker>()
.add_systems(OnEnter(PlayerMode::Normal), init_normal_mode)
.add_systems(
Update,
(dbg_handle_init_player.run_if(
in_state(PlayerMode::Uninitialized)
.and(in_state(DebugMode::Enabled).and(in_state(AppState::Ingame))),
),),
)
.init_state::<PlayerMode>();
}
const DEFAULT_PLAYER_SIZE: (f32, f32) = (0.3, 1.8);
fn init_normal_mode(
mut c: Commands,
tf: Single<&Transform, With<PlayerSpawnMarker>>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// c.spawn((Collider::cuboid(20., 1., 20.), RigidBody::Fixed));
c.spawn((
tf.clone(),
Mesh3d(meshes.add(Capsule3d::new(DEFAULT_PLAYER_SIZE.0, DEFAULT_PLAYER_SIZE.1))),
MeshMaterial3d(materials.add(Color::srgb(0., 1., 0.))),
Collider::capsule_y(DEFAULT_PLAYER_SIZE.1 / 2., DEFAULT_PLAYER_SIZE.0),
// Collider::cuboid(1., 1., 1.),
RigidBody::Dynamic,
// LockedAxes::ROTATION_LOCKED,
));
}
fn dbg_handle_init_player(
mut dbg_reader: EventReader<DebugEvent>,
mut state: ResMut<NextState<PlayerMode>>,
mut logger: ResMut<ConsoleLog>,
) {
for ev in dbg_reader.read() {
if let DebugEvent::InitPlayer { mode } = ev {
match mode {
PlayerMode::Uninitialized => {
logger.err("Can't initialize the Player as Uninitialized.")
}
other => {
state.set(*other);
logger.write(&format!("Player initialized as {mode:?}"));
}
};
}
}
}
/// Marks where the player spawns
#[derive(Component, Clone, Copy, Debug, Reflect)]
#[reflect(Component)]
struct PlayerSpawnMarker;
#[derive(Component, Clone, Debug)]
struct Player;

View file

@ -1,5 +1,5 @@
use bevy::prelude::*; use bevy::prelude::*;
use bevy_rapier3d::prelude::{Collider, RigidBody}; use bevy_rapier3d::prelude::{AdditionalMassProperties, Collider, RigidBody, Velocity};
use bevy_third_person_camera::ThirdPersonCameraTarget; use bevy_third_person_camera::ThirdPersonCameraTarget;
use log::info; use log::info;
@ -26,7 +26,10 @@ fn add_colliders_to_things_that_need_them(
) { ) {
for (entity, StaticColliderConfig { x, y, z }) in to_modify.iter() { for (entity, StaticColliderConfig { x, y, z }) in to_modify.iter() {
info!("meow"); info!("meow");
c.entity(entity) c.entity(entity).insert((
.insert(Collider::cuboid(*x / 2., *z / 2., -*y / 2.)); Collider::cuboid(*x / 2., *z / 2., -*y / 2.),
RigidBody::Fixed, // AdditionalMassProperties::default(),
// Velocity::default(),
));
} }
} }

View file

@ -22,21 +22,15 @@ enum AppState {
fn main() { fn main() {
App::new() App::new()
.register_type::<TPCTarget>()
.add_systems(Startup, camera::setup) .add_systems(Startup, camera::setup)
.add_plugins((DefaultPlugins, TextInputPlugin))
.add_plugins(( .add_plugins((
DefaultPlugins,
TextInputPlugin,
RapierPhysicsPlugin::<NoUserData>::default(), RapierPhysicsPlugin::<NoUserData>::default(),
game::plugin, SkeinPlugin::default(),
menus::plugin,
debug::plugin,
)) ))
.add_plugins(SkeinPlugin::default()) .add_plugins((game::plugin, menus::plugin, debug::plugin))
.init_state::<AppState>() .init_state::<AppState>()
.register_type::<AppState>() .register_type::<AppState>()
.run(); .run();
} }
#[derive(Debug, Reflect, Component)]
#[reflect(Component)]
struct TPCTarget;

View file

@ -3,3 +3,4 @@ log "hello from startup script!!"
enable-debug enable-debug
start-game start-game
load-scene gltf/test.gltf test load-scene gltf/test.gltf test
rapier