camera controller!!!

This commit is contained in:
TudbuT 2024-11-23 20:19:49 +01:00
parent b51241b1fc
commit 9e70d24779
3 changed files with 38 additions and 11 deletions

View file

@ -2,15 +2,16 @@ info section
block-size = 60
.P = [player]
.T = Blockgrau.png
.E = erdblock.png
.E = erdblock_lower.png
.G = grasblock_lower.png
._ = _grasblock_upper.png
., = _erdblock_upper.png
world section
TT
TTT P _______ ______ ___
TTTTTTTTTEEEGGGGGGGETEGGGGGGEGGGE
TTTTTTTTTTEEEEEEEEEEEEEEEEEEEEEEE
TTTTTTTEEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
T P
TT ,,,_______,,,______,___
TTTTTTTTEEEGGGGGGGEEEGGGGGGEGGGE
TTTTTTTTTEEEEEEEEEEEEEEEEEEEEEEE
TTTTTTEEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE

View file

@ -53,15 +53,19 @@ fn move_player(
kb_input: Res<ButtonInput<KeyCode>>,
mut query: Query<(
&mut Velocity,
&Transform,
&mut Player,
&mut KinematicCharacterController,
)>,
mut camera_query: Query<&mut Transform, (With<Camera2d>, Without<Player>)>,
time: Res<Time>,
) {
let (mut vel, mut player, mut controller) = query.single_mut();
let (mut vel, p_transform, mut player, mut controller) = query.single_mut();
let (mut cam_transform) = camera_query.single_mut();
if player.move_cooldown.tick(time.delta()).finished() {
let mut moved = false;
let mut mv = 0;
let mut jump = false;
if kb_input.pressed(KeyCode::KeyA) {
moved = true;
@ -72,6 +76,10 @@ fn move_player(
mv += 1;
}
let orig = cam_transform.translation;
println!("{orig:?}");
cam_transform.translation -= ((orig - p_transform.translation.xy().extend(0.0)) / 30.0);
if moved {
dbg!(mv);
controller.translation = Some(Vec2::new(mv as f32 * 6., 0.));
@ -139,6 +147,24 @@ fn add_player(
Velocity::default(),
))
.insert(KinematicCharacterController {
//translation: todo!(),
//custom_shape: todo!(),
//custom_mass: todo!(),
//up: todo!(),
//offset: todo!(),
//slide: todo!(),
//autostep: Some(CharacterAutostep {
// max_height: CharacterLength::Relative(0.1),
// min_width: CharacterLength::Absolute(1.0),
// include_dynamic_bodies: false,
//}),
//max_slope_climb_angle: todo!(),
//min_slope_slide_angle: todo!(),
//apply_impulse_to_dynamic_bodies: todo!(),
//snap_to_ground: Some(CharacterLength::Absolute(1.0)),
//filter_flags: todo!(),
//filter_groups: todo!(),
//normal_nudge_factor: todo!(),
..Default::default()
});
}

View file

@ -26,9 +26,9 @@ pub struct PlayerCoords {
impl PlayerCoords {
pub fn get_collider(&self) -> Collider {
let size = self.block_size * PLAYER_SIZE_FRACTION * 0.5;
let size = 0.5;
Collider::cuboid(size, size)
Collider::round_cuboid(size, size, 1.0)
}
}