mirror of
https://codeberg.org/schrottkatze/mgd2-tram-championships.git
synced 2025-07-05 03:17:39 +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
|
@ -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(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue