allow multiple players moving
This commit is contained in:
@@ -19,8 +19,8 @@ impl Plugin for CharacterControllerPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn apply_controls(character: Single<(&mut MoveInput, &MovementSpeedFactor, &Inputs)>) {
|
||||
let (mut char_input, factor, inputs) = character.into_inner();
|
||||
|
||||
char_input.set(inputs.look_dir * factor.0);
|
||||
pub fn apply_controls(mut query: Query<(&mut MoveInput, &MovementSpeedFactor, &Inputs)>) {
|
||||
for (mut char_input, factor, inputs) in query.iter_mut() {
|
||||
char_input.set(inputs.look_dir * factor.0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ fn rotate_view(
|
||||
}
|
||||
|
||||
fn apply_controls(
|
||||
character: Single<(
|
||||
mut query: Query<(
|
||||
&mut MoveInput,
|
||||
&mut Grounding,
|
||||
&mut KinematicVelocity,
|
||||
@@ -66,23 +66,24 @@ fn apply_controls(
|
||||
&Inputs,
|
||||
)>,
|
||||
) {
|
||||
let (mut move_input, mut grounding, mut velocity, mut flags, settings, move_factor, inputs) =
|
||||
character.into_inner();
|
||||
for (mut move_input, mut grounding, mut velocity, mut flags, settings, move_factor, inputs) in
|
||||
query.iter_mut()
|
||||
{
|
||||
let ground_normal = *grounding.normal().unwrap_or(Dir3::Y);
|
||||
|
||||
let ground_normal = *grounding.normal().unwrap_or(Dir3::Y);
|
||||
let mut direction = inputs.move_dir.extend(0.0).xzy();
|
||||
let look_dir_right = inputs.look_dir.cross(Vec3::Y);
|
||||
direction = (inputs.look_dir * direction.z) + (look_dir_right * direction.x);
|
||||
let y_projection = direction.project_onto(ground_normal);
|
||||
direction -= y_projection;
|
||||
direction = direction.normalize_or_zero();
|
||||
|
||||
let mut direction = inputs.move_dir.extend(0.0).xzy();
|
||||
let look_dir_right = inputs.look_dir.cross(Vec3::Y);
|
||||
direction = (inputs.look_dir * direction.z) + (look_dir_right * direction.x);
|
||||
let y_projection = direction.project_onto(ground_normal);
|
||||
direction -= y_projection;
|
||||
direction = direction.normalize_or_zero();
|
||||
move_input.set(direction * move_factor.0);
|
||||
|
||||
move_input.set(direction * move_factor.0);
|
||||
|
||||
if inputs.jump && grounding.is_grounded() {
|
||||
flags.jumping = true;
|
||||
flags.jump_count += 1;
|
||||
happy_feet::movement::jump(settings.jump_force, &mut velocity, &mut grounding, Dir3::Y)
|
||||
if inputs.jump && grounding.is_grounded() {
|
||||
flags.jumping = true;
|
||||
flags.jump_count += 1;
|
||||
happy_feet::movement::jump(settings.jump_force, &mut velocity, &mut grounding, Dir3::Y)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user