|
|
|
|
@ -94,6 +94,8 @@ enum PlayerState {
|
|
|
|
|
struct Tape {
|
|
|
|
|
translations: Vec<Vec3>,
|
|
|
|
|
rotations: Vec<Quat>,
|
|
|
|
|
linear_velocities: Vec<LinearVelocity>,
|
|
|
|
|
angular_velocities: Vec<AngularVelocity>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn init_bird(
|
|
|
|
|
@ -119,7 +121,6 @@ fn init_bird(
|
|
|
|
|
RigidBody::Static,
|
|
|
|
|
Collider::capsule(1.0, 1.0),
|
|
|
|
|
Mass(1.0),
|
|
|
|
|
ExternalForce::new(Vec3::X * 1.0).with_persistence(true),
|
|
|
|
|
ExternalImpulse::default().with_persistence(false),
|
|
|
|
|
LockedAxes::ROTATION_LOCKED.lock_translation_z(),
|
|
|
|
|
);
|
|
|
|
|
@ -271,7 +272,7 @@ fn flap(
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
bird.iter_mut().for_each(|(t, mut f)| {
|
|
|
|
|
f.apply_impulse(t.rotation * Vec3::NEG_Z * 5.0);
|
|
|
|
|
f.apply_impulse(t.rotation * Vec3::NEG_Z * 5.0 + t.rotation * Vec3::X);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -292,35 +293,43 @@ fn toggle_rewind(keycode: Res<ButtonInput<KeyCode>>, mut next: ResMut<NextState<
|
|
|
|
|
|
|
|
|
|
fn record(
|
|
|
|
|
#[cfg(debug_assertions)] state: Res<State<PlayerState>>,
|
|
|
|
|
mut birds: Query<(&Transform, &mut Tape), With<Bird>>,
|
|
|
|
|
mut birds: Query<(&Transform, &LinearVelocity, &AngularVelocity, &mut Tape), With<Bird>>,
|
|
|
|
|
) {
|
|
|
|
|
debug_assert!(
|
|
|
|
|
matches!(state.get(), PlayerState::Alive),
|
|
|
|
|
"Only record in the alive state"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
birds.iter_mut().for_each(|(transform, mut tape)| {
|
|
|
|
|
birds.iter_mut().for_each(|(transform, linear_velocity, angular_velocity, mut tape)| {
|
|
|
|
|
tape.translations.push(transform.translation);
|
|
|
|
|
tape.rotations.push(transform.rotation);
|
|
|
|
|
tape.linear_velocities.push(*linear_velocity);
|
|
|
|
|
tape.angular_velocities.push(*angular_velocity);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn rewind(
|
|
|
|
|
#[cfg(debug_assertions)] state: Res<State<PlayerState>>,
|
|
|
|
|
mut birds: Query<(&mut Transform, &mut Tape), With<Bird>>,
|
|
|
|
|
mut birds: Query<(&mut Transform, &mut AngularVelocity, &mut LinearVelocity, &mut Tape), With<Bird>>,
|
|
|
|
|
) {
|
|
|
|
|
debug_assert!(
|
|
|
|
|
matches!(state.get(), PlayerState::Rewind),
|
|
|
|
|
"Only rewind in the rewinding state"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
birds.iter_mut().for_each(|(mut transform, mut tape)| {
|
|
|
|
|
birds.iter_mut().for_each(|(mut transform, mut angular_velocity, mut linear_velocity, mut tape)| {
|
|
|
|
|
if let Some(t) = tape.translations.pop() {
|
|
|
|
|
transform.translation = t;
|
|
|
|
|
}
|
|
|
|
|
if let Some(r) = tape.rotations.pop() {
|
|
|
|
|
transform.rotation = r;
|
|
|
|
|
}
|
|
|
|
|
if let Some(av) = tape.angular_velocities.pop() {
|
|
|
|
|
*angular_velocity = av;
|
|
|
|
|
}
|
|
|
|
|
if let Some(lv) = tape.linear_velocities.pop() {
|
|
|
|
|
*linear_velocity = lv;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|