change WantsNo* to WantsMax*, cuz Icarus likes to rotate a bit

This commit is contained in:
yuni 2024-04-05 01:42:50 +02:00
parent 64423630da
commit 6b6cdccee7
3 changed files with 53 additions and 36 deletions

View file

@ -12,8 +12,8 @@ impl Plugin for ActorPlugin {
fn build(&self, app: &mut App) {
app.add_systems(FixedUpdate, (
update_physics_lifeforms,
handle_wants_norotation,
handle_wants_novelocity,
handle_wants_maxrotation,
handle_wants_maxvelocity,
));
app.add_systems(Update, (
handle_input,
@ -62,8 +62,8 @@ impl Default for Actor {
#[derive(Component)] pub struct InConversationWithPlayer;
#[derive(Component)] pub struct ActorEnteringVehicle;
#[derive(Component)] pub struct ActorVehicleBeingEntered;
#[derive(Component)] pub struct WantsNoRotation;
#[derive(Component)] pub struct WantsNoVelocity;
#[derive(Component)] pub struct WantsMaxRotation(pub f64);
#[derive(Component)] pub struct WantsMaxVelocity(pub f64);
#[derive(Component)]
pub struct LifeForm {
@ -300,16 +300,16 @@ fn handle_collisions(
}
}
fn handle_wants_norotation(
fn handle_wants_maxrotation(
//time: Res<Time>,
mut q_angularvelocity: Query<(&mut AngularVelocity, &Engine), With<WantsNoRotation>>,
mut query: Query<(&mut AngularVelocity, &Engine, &WantsMaxRotation)>,
) {
let epsilon = 0.0001;
//let d = time.delta_seconds();
for (mut v_ang, engine) in &mut q_angularvelocity {
for (mut v_ang, engine, maxrot) in &mut query {
let total = v_ang.0.length();
if total <= epsilon {
if total > 0.0 {
if total <= maxrot.0 + epsilon {
if total > maxrot.0 {
v_ang.0 = DVec3::splat(0.0);
}
}
@ -320,16 +320,16 @@ fn handle_wants_norotation(
}
}
fn handle_wants_novelocity(
fn handle_wants_maxvelocity(
time: Res<Time>,
mut q_velocity: Query<(&mut LinearVelocity, &Engine), With<WantsNoVelocity>>,
mut query: Query<(&mut LinearVelocity, &Engine, &WantsMaxVelocity)>,
) {
let dt = time.delta_seconds();
let epsilon = 0.0001;
for (mut v, engine) in &mut q_velocity {
for (mut v, engine, maxv) in &mut query {
let total = v.0.length();
if total <= epsilon {
if total > 0.0 {
if total <= maxv.0 + epsilon {
if total > maxv.0 {
v.0 = DVec3::splat(0.0);
}
// already not moving

View file

@ -49,8 +49,8 @@ struct ParserState {
is_suited: bool,
is_vehicle: bool,
has_physics: bool,
wants_norotation: bool,
wants_novelocity: bool,
wants_maxrotation: Option<f64>,
wants_maxvelocity: Option<f64>,
collider_is_mesh: bool,
thrust_forward: f32,
thrust_sideways: f32,
@ -101,8 +101,8 @@ impl Default for ParserState {
is_suited: false,
is_vehicle: false,
has_physics: true,
wants_norotation: false,
wants_novelocity: false,
wants_maxrotation: None,
wants_maxvelocity: None,
collider_is_mesh: false,
thrust_forward: default_engine.thrust_forward,
thrust_sideways: default_engine.thrust_forward,
@ -426,11 +426,25 @@ pub fn load_defs(
continue;
}
}
["wants", "norotation"] => {
state.wants_norotation = true;
["wants", "maxrotation", value] => {
// NOTE: requires an engine to slow down velocity
if let Ok(value_float) = value.parse::<f64>() {
state.wants_maxrotation = Some(value_float);
}
else {
error!("Can't parse float: {line}");
continue;
}
}
["wants", "novelocity"] => {
state.wants_novelocity = true;
["wants", "maxvelocity", value] => {
// NOTE: requires an engine to slow down velocity
if let Ok(value_float) = value.parse::<f64>() {
state.wants_maxvelocity = Some(value_float);
}
else {
error!("Can't parse float: {line}");
continue;
}
}
// Parsing chats
@ -622,13 +636,11 @@ fn spawn_entities(
..default()
});
}
if state.wants_norotation {
// NOTE: requires an engine to slow down rotation
actor.insert(actor::WantsNoRotation);
if let Some(value) = state.wants_maxrotation {
actor.insert(actor::WantsMaxRotation(value));
}
if state.wants_novelocity {
// NOTE: requires an engine to slow down velocity
actor.insert(actor::WantsNoVelocity);
if let Some(value) = state.wants_maxvelocity {
actor.insert(actor::WantsMaxVelocity(value));
}
if let Some(color) = state.light_color {
actor.insert(PointLightBundle {
@ -651,7 +663,12 @@ fn spawn_entities(
if state.is_vehicle {
actor.insert(actor::Vehicle::default());
}
if state.is_vehicle || state.is_suited {
if state.is_vehicle || state.is_suited
|| state.thrust_forward > 0.0
|| state.thrust_sideways > 0.0
|| state.thrust_back > 0.0
|| state.reaction_wheels > 0.0
{
actor.insert(actor::Engine {
thrust_forward: state.thrust_forward,
thrust_back: state.thrust_back,

View file

@ -90,8 +90,8 @@ actor 3000 0 0 moonlet
actor -200 -110 1000 satellite
relativeto player
scale 40
wants norotation
thrust 0 0 0 300 1
wants maxrotation 0
thrust 0 0 0 30 1
collider capsule 7.5 1
rotationy 0.5
angularmomentum 0 0 0
@ -157,8 +157,8 @@ actor -3300 10 0 pizzeria
mass 200.0
collider capsule 2 1
thrust 1.2 1 1 10 1.5
wants norotation
wants novelocity
wants maxrotation 0
wants maxvelocity 0
pronoun he
chat pizzeria
name "Space Pizza™"
@ -212,10 +212,10 @@ actor 70 -25 -60 suit
alive yes
mass 200.0
collider capsule 2 1
angularmomentum 0.1 0.2 0.1
angularmomentum 0.4 0.2 0.1
thrust 1.2 1 1 10 1.5
wants norotation
wants novelocity
wants maxrotation 0.5
wants maxvelocity 0
pronoun it
chat hi_icarus
name Icarus