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)>) {
|
pub fn apply_controls(mut query: Query<(&mut MoveInput, &MovementSpeedFactor, &Inputs)>) {
|
||||||
let (mut char_input, factor, inputs) = character.into_inner();
|
for (mut char_input, factor, inputs) in query.iter_mut() {
|
||||||
|
char_input.set(inputs.look_dir * factor.0);
|
||||||
char_input.set(inputs.look_dir * factor.0);
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ fn rotate_view(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn apply_controls(
|
fn apply_controls(
|
||||||
character: Single<(
|
mut query: Query<(
|
||||||
&mut MoveInput,
|
&mut MoveInput,
|
||||||
&mut Grounding,
|
&mut Grounding,
|
||||||
&mut KinematicVelocity,
|
&mut KinematicVelocity,
|
||||||
@@ -66,23 +66,24 @@ fn apply_controls(
|
|||||||
&Inputs,
|
&Inputs,
|
||||||
)>,
|
)>,
|
||||||
) {
|
) {
|
||||||
let (mut move_input, mut grounding, mut velocity, mut flags, settings, move_factor, inputs) =
|
for (mut move_input, mut grounding, mut velocity, mut flags, settings, move_factor, inputs) in
|
||||||
character.into_inner();
|
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();
|
move_input.set(direction * move_factor.0);
|
||||||
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);
|
if inputs.jump && grounding.is_grounded() {
|
||||||
|
flags.jumping = true;
|
||||||
if inputs.jump && grounding.is_grounded() {
|
flags.jump_count += 1;
|
||||||
flags.jumping = true;
|
happy_feet::movement::jump(settings.jump_force, &mut velocity, &mut grounding, Dir3::Y)
|
||||||
flags.jump_count += 1;
|
}
|
||||||
happy_feet::movement::jump(settings.jump_force, &mut velocity, &mut grounding, Dir3::Y)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user