mirror of
https://codeberg.org/schrottkatze/mgd2-tram-championships.git
synced 2025-07-01 09:27:38 +00:00
i have not the slightest idea why this is blowing up in my face rn
This commit is contained in:
parent
324f1c04ed
commit
8f6e24875a
12 changed files with 210 additions and 88 deletions
Binary file not shown.
|
@ -3,50 +3,72 @@
|
|||
"generator":"Khronos glTF Blender I/O v4.4.56",
|
||||
"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,
|
||||
"scenes":[
|
||||
{
|
||||
"extras":{
|
||||
"skein_extension_properties":{
|
||||
"enabled":1
|
||||
}
|
||||
},
|
||||
"name":"Scene",
|
||||
"nodes":[
|
||||
0,
|
||||
1
|
||||
1,
|
||||
2,
|
||||
3
|
||||
]
|
||||
}
|
||||
],
|
||||
"nodes":[
|
||||
{
|
||||
"extensions":{
|
||||
"KHR_lights_punctual":{
|
||||
"light":0
|
||||
}
|
||||
},
|
||||
"name":"Light",
|
||||
"rotation":[
|
||||
-0.28416627645492554,
|
||||
0.7269423007965088,
|
||||
0.34203392267227173,
|
||||
0.5232754945755005
|
||||
],
|
||||
"translation":[
|
||||
4.076245307922363,
|
||||
5.903861999511719,
|
||||
-1.0054539442062378
|
||||
]
|
||||
},
|
||||
{
|
||||
"extras":{
|
||||
"skein_two":[
|
||||
{
|
||||
"name":"TPCTarget",
|
||||
"selected_type_path":"mgd2_demonic_posession::TPCTarget"
|
||||
},
|
||||
{
|
||||
"name":"StaticColliderConfig",
|
||||
"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":[
|
||||
{
|
||||
"mgd2_demonic_posession::TPCTarget":{}
|
||||
},
|
||||
{
|
||||
"mgd2_demonic_posession::game::scene::StaticColliderConfig":{
|
||||
"x":10.0,
|
||||
"y":5.0,
|
||||
"y":15.0,
|
||||
"z":1.0
|
||||
}
|
||||
},
|
||||
{
|
||||
"bevy_rapier3d::dynamics::rigid_body::RigidBody":"Fixed"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -55,18 +77,6 @@
|
|||
},
|
||||
{
|
||||
"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":[
|
||||
{
|
||||
"mgd2_demonic_posession::game::scene::StaticColliderConfig":{
|
||||
|
@ -88,7 +98,22 @@
|
|||
"translation":[
|
||||
0,
|
||||
1.5,
|
||||
0
|
||||
3
|
||||
]
|
||||
},
|
||||
{
|
||||
"extras":{
|
||||
"skein":[
|
||||
{
|
||||
"mgd2_demonic_posession::game::player::PlayerSpawnMarker":{}
|
||||
}
|
||||
]
|
||||
},
|
||||
"name":"Empty",
|
||||
"translation":[
|
||||
0,
|
||||
3,
|
||||
-4
|
||||
]
|
||||
}
|
||||
],
|
||||
|
@ -128,12 +153,12 @@
|
|||
"max":[
|
||||
5,
|
||||
0.5,
|
||||
2.5
|
||||
7.5
|
||||
],
|
||||
"min":[
|
||||
-5,
|
||||
-0.5,
|
||||
-2.5
|
||||
-7.5
|
||||
],
|
||||
"type":"VEC3"
|
||||
},
|
||||
|
|
Binary file not shown.
|
@ -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)
|
||||
/// This camera is also used for menu rendering etc.
|
||||
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),
|
||||
));
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ use std::path::PathBuf;
|
|||
use bevy::prelude::*;
|
||||
use clap::Subcommand;
|
||||
|
||||
use crate::game::PlayerMode;
|
||||
|
||||
#[derive(Event, Debug, Subcommand, PartialEq, Eq)]
|
||||
pub enum DebugEvent {
|
||||
/// Close the debug console.
|
||||
|
@ -54,7 +56,7 @@ pub enum DebugEvent {
|
|||
#[command(name = "enable-debug", aliases = ["debug-enable"])]
|
||||
EnableDebugMode,
|
||||
|
||||
/// Load a gltf scene.
|
||||
/// Load a gltf scene. Requires debug mode.
|
||||
///
|
||||
/// Auto-reloading isn't possible due to engine reasons, see:
|
||||
/// https://github.com/bevyengine/bevy/pull/18358
|
||||
|
@ -72,4 +74,7 @@ pub enum DebugEvent {
|
|||
/// Toggles rapier debug mode
|
||||
#[command(aliases = ["rapier-debug", "rapier"])]
|
||||
DebugRapier,
|
||||
|
||||
/// Manually call player initialisation
|
||||
InitPlayer { mode: PlayerMode },
|
||||
}
|
||||
|
|
|
@ -3,13 +3,15 @@ use bevy::prelude::*;
|
|||
use crate::{
|
||||
AppState,
|
||||
cleanup::{self, despawn},
|
||||
debug::DebugMode,
|
||||
};
|
||||
|
||||
mod camera;
|
||||
mod debug;
|
||||
mod player;
|
||||
mod scene;
|
||||
|
||||
pub use player::PlayerMode;
|
||||
|
||||
/// Gameplay system set. All functions in this control the gameplay (duh).
|
||||
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||
struct GameplaySet;
|
||||
|
@ -19,6 +21,7 @@ pub fn plugin(app: &mut App) {
|
|||
OnExit(AppState::Ingame),
|
||||
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)));
|
||||
}
|
||||
|
|
|
@ -8,37 +8,37 @@ use crate::AppState;
|
|||
use super::GameplaySet;
|
||||
|
||||
pub fn plugin(app: &mut App) {
|
||||
app.add_plugins(ThirdPersonCameraPlugin)
|
||||
.add_systems(
|
||||
OnEnter(AppState::Ingame),
|
||||
setup_game_camera.in_set(GameplaySet),
|
||||
)
|
||||
// .add_systems(Update, auto_target)
|
||||
.add_systems(OnExit(AppState::Ingame), remove_tpc.in_set(GameplaySet));
|
||||
// app.add_plugins()
|
||||
// .add_systems(
|
||||
// OnEnter(AppState::Ingame),
|
||||
// setup_game_camera.in_set(GameplaySet),
|
||||
// )
|
||||
// .add_systems(Update, auto_target)
|
||||
// .add_systems(OnExit(AppState::Ingame), remove_tpc.in_set(GameplaySet));
|
||||
}
|
||||
|
||||
/// Adds [ThirdPersonCamera] to our existing camera.
|
||||
pub fn setup_game_camera(mut c: Commands, cam: Single<Entity, With<Camera3d>>) {
|
||||
c.entity(*cam).insert(ThirdPersonCamera {
|
||||
cursor_lock_key: KeyCode::Space,
|
||||
cursor_lock_toggle_enabled: true,
|
||||
gamepad_settings: CustomGamepadSettings::default(),
|
||||
cursor_lock_active: true,
|
||||
sensitivity: Vec2::new(1.0, 1.0),
|
||||
mouse_orbit_button_enabled: true,
|
||||
mouse_orbit_button: MouseButton::Middle,
|
||||
offset_enabled: false,
|
||||
offset: Offset::new(0.5, 0.4),
|
||||
offset_toggle_enabled: false,
|
||||
offset_toggle_speed: 5.0,
|
||||
offset_toggle_key: KeyCode::KeyE,
|
||||
zoom_enabled: true,
|
||||
zoom: Zoom::new(1.5, 30.0),
|
||||
zoom_sensitivity: 1.0,
|
||||
..Default::default()
|
||||
});
|
||||
info!("Third person camera set up!")
|
||||
}
|
||||
// pub fn setup_game_camera(mut c: Commands, cam: Single<Entity, With<Camera3d>>) {
|
||||
// c.entity(*cam).insert(ThirdPersonCamera {
|
||||
// cursor_lock_key: KeyCode::Space,
|
||||
// cursor_lock_toggle_enabled: true,
|
||||
// gamepad_settings: CustomGamepadSettings::default(),
|
||||
// cursor_lock_active: true,
|
||||
// sensitivity: Vec2::new(1.0, 1.0),
|
||||
// mouse_orbit_button_enabled: true,
|
||||
// mouse_orbit_button: MouseButton::Middle,
|
||||
// offset_enabled: false,
|
||||
// offset: Offset::new(0.5, 0.4),
|
||||
// offset_toggle_enabled: false,
|
||||
// offset_toggle_speed: 5.0,
|
||||
// offset_toggle_key: KeyCode::KeyE,
|
||||
// zoom_enabled: true,
|
||||
// zoom: Zoom::new(1.5, 30.0),
|
||||
// zoom_sensitivity: 1.0,
|
||||
// ..Default::default()
|
||||
// });
|
||||
// info!("Third person camera set up!")
|
||||
// }
|
||||
|
||||
// fn auto_target(
|
||||
// mut c: Commands,
|
||||
|
|
|
@ -4,7 +4,7 @@ use bevy::{
|
|||
asset::{AssetPath, io::AssetSourceEvent},
|
||||
prelude::*,
|
||||
};
|
||||
use bevy_rapier3d::render::DebugRenderContext;
|
||||
use bevy_rapier3d::{prelude::RigidBody, render::DebugRenderContext};
|
||||
|
||||
use crate::debug::{ConsoleLog, DebugEvent, DebugMode};
|
||||
|
||||
|
@ -37,7 +37,11 @@ fn handle_load_gltf(
|
|||
let scene_handle = asset_server
|
||||
.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 {
|
||||
scene.insert(Id(id.clone()));
|
||||
|
|
84
src/game/player.rs
Normal file
84
src/game/player.rs
Normal 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;
|
|
@ -1,5 +1,5 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy_rapier3d::prelude::{Collider, RigidBody};
|
||||
use bevy_rapier3d::prelude::{AdditionalMassProperties, Collider, RigidBody, Velocity};
|
||||
use bevy_third_person_camera::ThirdPersonCameraTarget;
|
||||
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() {
|
||||
info!("meow");
|
||||
c.entity(entity)
|
||||
.insert(Collider::cuboid(*x / 2., *z / 2., -*y / 2.));
|
||||
c.entity(entity).insert((
|
||||
Collider::cuboid(*x / 2., *z / 2., -*y / 2.),
|
||||
RigidBody::Fixed, // AdditionalMassProperties::default(),
|
||||
// Velocity::default(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -22,21 +22,15 @@ enum AppState {
|
|||
|
||||
fn main() {
|
||||
App::new()
|
||||
.register_type::<TPCTarget>()
|
||||
.add_systems(Startup, camera::setup)
|
||||
.add_plugins((DefaultPlugins, TextInputPlugin))
|
||||
.add_plugins((
|
||||
DefaultPlugins,
|
||||
TextInputPlugin,
|
||||
RapierPhysicsPlugin::<NoUserData>::default(),
|
||||
game::plugin,
|
||||
menus::plugin,
|
||||
debug::plugin,
|
||||
SkeinPlugin::default(),
|
||||
))
|
||||
.add_plugins(SkeinPlugin::default())
|
||||
.add_plugins((game::plugin, menus::plugin, debug::plugin))
|
||||
.init_state::<AppState>()
|
||||
.register_type::<AppState>()
|
||||
.run();
|
||||
}
|
||||
|
||||
#[derive(Debug, Reflect, Component)]
|
||||
#[reflect(Component)]
|
||||
struct TPCTarget;
|
||||
|
|
|
@ -3,3 +3,4 @@ log "hello from startup script!!"
|
|||
enable-debug
|
||||
start-game
|
||||
load-scene gltf/test.gltf test
|
||||
rapier
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue