implement rotation of objects

This commit is contained in:
yuni 2024-03-19 16:14:12 +01:00
parent cc8734e793
commit caa53fdb59
2 changed files with 20 additions and 4 deletions

View file

@ -10,7 +10,10 @@ impl Plugin for ActorPlugin {
app.add_systems(Startup, setup);
app.register_type::<ChatBranch>();
app.register_type::<ChatChoice>();
app.add_systems(FixedUpdate, update);
app.add_systems(FixedUpdate, (
update_physics_lifeforms,
update_physics_actors,
));
app.add_systems(Update, (
handle_new_conversations,
handle_conversations,
@ -30,7 +33,7 @@ pub struct Actor {
pub hp: f32,
pub m: f32, // mass
pub v: Vec3, // velocity
// TODO: rotation
pub angular_momentum: Quat,
}
impl Default for Actor {
@ -39,6 +42,7 @@ impl Default for Actor {
hp: 100.0,
m: 100.0,
v: Vec3::ZERO,
angular_momentum: Quat::from_euler(EulerRot::XYZ, 0.001, 0.01, 0.003),
}
}
}
@ -118,7 +122,16 @@ pub fn setup(
});
}
pub fn update(
pub fn update_physics_actors(
time: Res<Time>,
mut q_actors: Query<(&mut Actor, &mut Transform)>,
) {
for (actor, mut transform) in q_actors.iter_mut() {
transform.rotate(actor.angular_momentum);
}
}
pub fn update_physics_lifeforms(
time: Res<Time>,
mut query: Query<(&mut LifeForm, &mut Suit)>,
) {

View file

@ -68,7 +68,10 @@ pub fn setup(
// Add player
commands.spawn((
actor::Player,
actor::Actor::default(),
actor::Actor {
angular_momentum: Quat::IDENTITY,
..default()
},
actor::LifeForm::default(),
actor::Suit {
oxygen: nature::OXY_M,