player physics!!!!
This commit is contained in:
parent
6cdeb38ba4
commit
3f47f0305e
2 changed files with 33 additions and 11 deletions
|
@ -34,7 +34,12 @@ enum PlayerAnimations {
|
||||||
Walk,
|
Walk,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_player(
|
// fn move_player(
|
||||||
|
// kb_input: Res<ButtonInput<KeyCode>>,
|
||||||
|
// mut query:
|
||||||
|
// )
|
||||||
|
|
||||||
|
fn add_player(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||||
|
@ -76,15 +81,24 @@ pub fn add_player(
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
commands.spawn((
|
commands
|
||||||
Player,
|
.spawn((
|
||||||
AnimBundle {
|
Player,
|
||||||
tag: PlayerAnimations::Idle,
|
AnimBundle {
|
||||||
mgr: anims,
|
tag: PlayerAnimations::Idle,
|
||||||
},
|
mgr: anims,
|
||||||
SpriteBundle {
|
},
|
||||||
transform: (*player_coords).into(),
|
SpriteBundle {
|
||||||
|
transform: (*player_coords).into(),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.insert((
|
||||||
|
RigidBody::Dynamic,
|
||||||
|
player_coords.get_collider(),
|
||||||
|
Velocity::default(),
|
||||||
|
))
|
||||||
|
.insert(KinematicCharacterController {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
});
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,14 @@ pub struct PlayerCoords {
|
||||||
block_size: f32,
|
block_size: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PlayerCoords {
|
||||||
|
pub fn get_collider(&self) -> Collider {
|
||||||
|
let size = self.block_size * PLAYER_SIZE_FRACTION * 0.5;
|
||||||
|
|
||||||
|
Collider::cuboid(size, size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<PlayerCoords> for Transform {
|
impl From<PlayerCoords> for Transform {
|
||||||
fn from(val: PlayerCoords) -> Self {
|
fn from(val: PlayerCoords) -> Self {
|
||||||
let PlayerCoords { x, y, block_size } = val;
|
let PlayerCoords { x, y, block_size } = val;
|
||||||
|
|
Loading…
Add table
Reference in a new issue