jumping, character controller fixes
This commit is contained in:
parent
6956df3d3b
commit
126325de8f
3 changed files with 20 additions and 12 deletions
|
@ -58,30 +58,37 @@ fn move_player(
|
|||
&mut KinematicCharacterController,
|
||||
)>,
|
||||
mut camera_query: Query<&mut Transform, (With<Camera2d>, Without<Player>)>,
|
||||
phys: Query<&KinematicCharacterControllerOutput>,
|
||||
player_coords: Res<PlayerCoords>,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
let (mut vel, p_transform, mut player, mut controller) = query.single_mut();
|
||||
let (mut cam_transform) = camera_query.single_mut();
|
||||
let (output) = phys.get_single();
|
||||
if player.move_cooldown.tick(time.delta()).finished() {
|
||||
let mut moved = false;
|
||||
let mut mv = 0;
|
||||
let mut move_x = 0;
|
||||
let mut move_y = 0;
|
||||
let mut jump = false;
|
||||
|
||||
if kb_input.pressed(KeyCode::KeyA) {
|
||||
moved = true;
|
||||
mv -= 1;
|
||||
move_x -= 1;
|
||||
}
|
||||
if kb_input.pressed(KeyCode::KeyD) {
|
||||
moved = true;
|
||||
mv += 1;
|
||||
move_x += 1;
|
||||
}
|
||||
if kb_input.pressed(KeyCode::Space) && output.is_ok_and(|x| x.grounded) {
|
||||
moved = true;
|
||||
move_y += 1;
|
||||
}
|
||||
|
||||
let orig = cam_transform.translation;
|
||||
cam_transform.translation -= ((orig - p_transform.translation.xy().extend(0.0)) / 30.0);
|
||||
|
||||
if moved {
|
||||
controller.translation = Some(Vec2::new(mv as f32 * 6., 0.));
|
||||
}
|
||||
controller.translation = Some(Vec2::new(move_x as f32 * 6., 0. - 0.01));
|
||||
vel.linvel += Vec2::new(0., move_y as f32 * 3. * METER);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,6 +149,7 @@ fn add_player(
|
|||
.insert((
|
||||
RigidBody::Dynamic,
|
||||
player_coords.get_collider(),
|
||||
LockedAxes::ROTATION_LOCKED,
|
||||
Velocity::default(),
|
||||
))
|
||||
.insert(KinematicCharacterController {
|
||||
|
@ -159,7 +167,7 @@ fn add_player(
|
|||
//max_slope_climb_angle: todo!(),
|
||||
//min_slope_slide_angle: todo!(),
|
||||
//apply_impulse_to_dynamic_bodies: todo!(),
|
||||
// snap_to_ground: Some(CharacterLength::Absolute(100.0)),
|
||||
snap_to_ground: Some(CharacterLength::Absolute(0.5)),
|
||||
//filter_flags: todo!(),
|
||||
//filter_groups: todo!(),
|
||||
// normal_nudge_factor: 1.,
|
||||
|
|
|
@ -19,9 +19,9 @@ struct Block;
|
|||
|
||||
#[derive(Resource, Default, Clone, Copy)]
|
||||
pub struct PlayerCoords {
|
||||
x: f32,
|
||||
y: f32,
|
||||
block_size: f32,
|
||||
pub x: f32,
|
||||
pub y: f32,
|
||||
pub block_size: f32,
|
||||
}
|
||||
|
||||
impl PlayerCoords {
|
||||
|
|
|
@ -5,7 +5,7 @@ use game::game_plugin;
|
|||
|
||||
mod game;
|
||||
|
||||
const METER: f32 = 30.;
|
||||
const METER: f32 = 60.;
|
||||
|
||||
#[derive(States, Debug, Clone, PartialEq, Eq, Hash, Default)]
|
||||
enum AppState {
|
||||
|
@ -26,7 +26,7 @@ fn main() {
|
|||
let rapier_config = RapierConfiguration {
|
||||
scaled_shape_subdivision: 10,
|
||||
timestep_mode: TimestepMode::Variable {
|
||||
max_dt: 0.1,
|
||||
max_dt: 0.5,
|
||||
time_scale: 1.0,
|
||||
substeps: 20,
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue