implement rotation of objects
This commit is contained in:
parent
cc8734e793
commit
caa53fdb59
19
src/actor.rs
19
src/actor.rs
|
@ -10,7 +10,10 @@ impl Plugin for ActorPlugin {
|
||||||
app.add_systems(Startup, setup);
|
app.add_systems(Startup, setup);
|
||||||
app.register_type::<ChatBranch>();
|
app.register_type::<ChatBranch>();
|
||||||
app.register_type::<ChatChoice>();
|
app.register_type::<ChatChoice>();
|
||||||
app.add_systems(FixedUpdate, update);
|
app.add_systems(FixedUpdate, (
|
||||||
|
update_physics_lifeforms,
|
||||||
|
update_physics_actors,
|
||||||
|
));
|
||||||
app.add_systems(Update, (
|
app.add_systems(Update, (
|
||||||
handle_new_conversations,
|
handle_new_conversations,
|
||||||
handle_conversations,
|
handle_conversations,
|
||||||
|
@ -30,7 +33,7 @@ pub struct Actor {
|
||||||
pub hp: f32,
|
pub hp: f32,
|
||||||
pub m: f32, // mass
|
pub m: f32, // mass
|
||||||
pub v: Vec3, // velocity
|
pub v: Vec3, // velocity
|
||||||
// TODO: rotation
|
pub angular_momentum: Quat,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Actor {
|
impl Default for Actor {
|
||||||
|
@ -39,6 +42,7 @@ impl Default for Actor {
|
||||||
hp: 100.0,
|
hp: 100.0,
|
||||||
m: 100.0,
|
m: 100.0,
|
||||||
v: Vec3::ZERO,
|
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>,
|
time: Res<Time>,
|
||||||
mut query: Query<(&mut LifeForm, &mut Suit)>,
|
mut query: Query<(&mut LifeForm, &mut Suit)>,
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -68,7 +68,10 @@ pub fn setup(
|
||||||
// Add player
|
// Add player
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
actor::Player,
|
actor::Player,
|
||||||
actor::Actor::default(),
|
actor::Actor {
|
||||||
|
angular_momentum: Quat::IDENTITY,
|
||||||
|
..default()
|
||||||
|
},
|
||||||
actor::LifeForm::default(),
|
actor::LifeForm::default(),
|
||||||
actor::Suit {
|
actor::Suit {
|
||||||
oxygen: nature::OXY_M,
|
oxygen: nature::OXY_M,
|
||||||
|
|
Loading…
Reference in a new issue