fix physics

This commit is contained in:
TudbuT 2024-11-23 21:02:15 +01:00
parent dc7b86157d
commit 6956df3d3b
4 changed files with 22 additions and 10 deletions

View file

@ -10,7 +10,7 @@ mod scene;
mod set; mod set;
pub const WORLD_DEPTH: f32 = 0.5; pub const WORLD_DEPTH: f32 = 0.5;
pub const PLAYER_DEPTH: f32 = 0.5; pub const PLAYER_DEPTH: f32 = 0.4;
pub const PLAYER_SIZE_FRACTION: f32 = 0.8; pub const PLAYER_SIZE_FRACTION: f32 = 0.8;
pub fn game_plugin(app: &mut App) { pub fn game_plugin(app: &mut App) {

View file

@ -34,7 +34,7 @@ impl FromWorld for PlayerSpawnOneshot {
} }
pub(super) fn player_plugin(app: &mut App) { pub(super) fn player_plugin(app: &mut App) {
app.add_systems(Update, (move_player, debug_player_pos)) app.add_systems(Update, (move_player,))
.init_resource::<PlayerSpawnOneshot>(); .init_resource::<PlayerSpawnOneshot>();
} }
@ -77,11 +77,9 @@ fn move_player(
} }
let orig = cam_transform.translation; let orig = cam_transform.translation;
println!("{orig:?}");
cam_transform.translation -= ((orig - p_transform.translation.xy().extend(0.0)) / 30.0); cam_transform.translation -= ((orig - p_transform.translation.xy().extend(0.0)) / 30.0);
if moved { if moved {
dbg!(mv);
controller.translation = Some(Vec2::new(mv as f32 * 6., 0.)); controller.translation = Some(Vec2::new(mv as f32 * 6., 0.));
} }
} }
@ -151,8 +149,8 @@ fn add_player(
//custom_shape: todo!(), //custom_shape: todo!(),
//custom_mass: todo!(), //custom_mass: todo!(),
//up: todo!(), //up: todo!(),
//offset: todo!(), offset: CharacterLength::Absolute(0.01),
//slide: todo!(), slide: true,
//autostep: Some(CharacterAutostep { //autostep: Some(CharacterAutostep {
// max_height: CharacterLength::Relative(0.1), // max_height: CharacterLength::Relative(0.1),
// min_width: CharacterLength::Absolute(1.0), // min_width: CharacterLength::Absolute(1.0),
@ -161,10 +159,10 @@ fn add_player(
//max_slope_climb_angle: todo!(), //max_slope_climb_angle: todo!(),
//min_slope_slide_angle: todo!(), //min_slope_slide_angle: todo!(),
//apply_impulse_to_dynamic_bodies: todo!(), //apply_impulse_to_dynamic_bodies: todo!(),
//snap_to_ground: Some(CharacterLength::Absolute(1.0)), // snap_to_ground: Some(CharacterLength::Absolute(100.0)),
//filter_flags: todo!(), //filter_flags: todo!(),
//filter_groups: todo!(), //filter_groups: todo!(),
//normal_nudge_factor: todo!(), // normal_nudge_factor: 1.,
..Default::default() ..Default::default()
}); });
} }

View file

@ -28,7 +28,8 @@ impl PlayerCoords {
pub fn get_collider(&self) -> Collider { pub fn get_collider(&self) -> Collider {
let size = 0.5; let size = 0.5;
Collider::round_cuboid(size, size, 1.0) Collider::round_cuboid(size, size, 1.5)
// Collider::cuboid(size, size)
} }
} }

View file

@ -5,7 +5,7 @@ use game::game_plugin;
mod game; mod game;
const METER: f32 = 60.; const METER: f32 = 30.;
#[derive(States, Debug, Clone, PartialEq, Eq, Hash, Default)] #[derive(States, Debug, Clone, PartialEq, Eq, Hash, Default)]
enum AppState { enum AppState {
@ -23,6 +23,18 @@ enum PausedState {
} }
fn main() { fn main() {
let rapier_config = RapierConfiguration {
scaled_shape_subdivision: 10,
timestep_mode: TimestepMode::Variable {
max_dt: 0.1,
time_scale: 1.0,
substeps: 20,
},
gravity: Vec2::new(0.0, -9.81 * METER),
physics_pipeline_active: true,
query_pipeline_active: true,
force_update_from_transform_changes: false,
};
App::new() App::new()
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins)
.add_plugins(RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(METER)) .add_plugins(RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(METER))
@ -32,6 +44,7 @@ fn main() {
.init_state::<AppState>() .init_state::<AppState>()
.init_state::<PausedState>() .init_state::<PausedState>()
.insert_state(AppState::InGame) // TODO dont .insert_state(AppState::InGame) // TODO dont
.insert_resource(rapier_config)
.run(); .run();
} }