Added carriage

This commit is contained in:
Joshua Barretto 2023-05-24 21:09:42 +01:00
parent 623ab099b8
commit 8a8a5526f1
12 changed files with 81 additions and 6 deletions

View File

@ -179,6 +179,42 @@
central: ("submarine.rudder"),
),
custom_indices: {
1: Air(ChairSingle, 4),
2: Air(Helm, 0),
3: Air(Door, 4),
4: Air(Door, 0),
9: Air(CraftingBench, 0),
10: Air(Window1, 0),
11: Air(RepairBench, 0),
12: Air(DismantlingBench, 4),
13: Air(Window1, 2),
14: Air(Crate, 0),
15: Air(Cauldron, 2),
16: Air(Tent, 0),
17: Air(CookingPot, 0),
18: Air(WallLampSmall, 4),
19: Air(Lantern, 4),
},
),
Carriage: (
bone0: (
offset: (-4.5, -6.5, -0.5),
central: ("carriage.structure"),
),
bone1: (
offset: (0.0, 0.0, 0.0),
central: ("empty"),
),
bone2: (
offset: (0.0, 0.0, 0.0),
central: ("empty"),
),
bone3: (
offset: (0.0, 0.0, 0.0),
central: ("empty"),
),
custom_indices: {
1: Air(ChairSingle, 4),
2: Air(Helm, 0),

BIN
assets/common/voxel/carriage/prop.vox (Stored with Git LFS) Normal file

Binary file not shown.

BIN
assets/common/voxel/carriage/rudder.vox (Stored with Git LFS) Normal file

Binary file not shown.

BIN
assets/common/voxel/carriage/structure.vox (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -1099,6 +1099,7 @@ impl Body {
ship::Body::Galleon => [-2.0, -5.0, 4.0],
ship::Body::Skiff => [1.0, -2.0, 2.0],
ship::Body::Submarine => [1.0, -2.0, 2.0],
ship::Body::Carriage => [1.0, -2.0, 2.0],
ship::Body::Volume => [0.0, 0.0, 0.0],
},
_ => [0.0, 0.0, 0.0],

View File

@ -19,7 +19,7 @@ pub const ALL_BODIES: [Body; 6] = [
];
pub const ALL_AIRSHIPS: [Body; 2] = [Body::DefaultAirship, Body::AirBalloon];
pub const ALL_SHIPS: [Body; 4] = [Body::SailBoat, Body::Galleon, Body::Skiff, Body::Submarine];
pub const ALL_SHIPS: [Body; 5] = [Body::SailBoat, Body::Galleon, Body::Skiff, Body::Submarine, Body::Carriage];
make_case_elim!(
body,
@ -33,6 +33,7 @@ make_case_elim!(
Volume = 4,
Skiff = 5,
Submarine = 6,
Carriage = 7,
}
);
@ -64,6 +65,7 @@ impl Body {
Body::Galleon => Some("galleon.structure"),
Body::Skiff => Some("skiff.structure"),
Body::Submarine => Some("submarine.structure"),
Body::Carriage => Some("carriage.structure"),
Body::Volume => None,
}
}
@ -76,6 +78,7 @@ impl Body {
Body::Galleon => Vec3::new(14.0, 48.0, 10.0),
Body::Skiff => Vec3::new(7.0, 15.0, 10.0),
Body::Submarine => Vec3::new(2.0, 15.0, 8.0),
Body::Carriage => Vec3::new(2.0, 15.0, 8.0),
}
}
@ -109,6 +112,7 @@ impl Body {
match self {
Body::DefaultAirship | Body::AirBalloon | Body::Volume => Density(AIR_DENSITY),
Body::Submarine => Density(WATER_DENSITY), // Neutrally buoyant
Body::Carriage => Density(WATER_DENSITY * 0.5),
_ => Density(AIR_DENSITY * 0.95 + WATER_DENSITY * 0.05), /* Most boats should be very
* buoyant */
}
@ -123,7 +127,7 @@ impl Body {
pub fn flying_height(&self) -> f32 { if self.can_fly() { 200.0 } else { 0.0 } }
pub fn has_water_thrust(&self) -> bool {
!self.can_fly() // TODO: Differentiate this more carefully
!self.can_fly() && !matches!(self, Body::Carriage) // TODO: Differentiate this more carefully
}
pub fn make_collider(&self) -> Collider {

View File

@ -63,6 +63,7 @@ pub struct PreviousPhysCache {
pub origins: Option<(Vec2<f32>, Vec2<f32>)>,
pub pos: Option<Pos>,
pub ori: Quaternion<f32>,
pub pos_interp: Option<Pos>,
}
impl Component for PreviousPhysCache {

View File

@ -6,7 +6,7 @@ use crate::{
ActiveAbilities, Beam, Body, CharacterActivity, CharacterState, Combo, ControlAction,
Controller, ControllerInputs, Density, Energy, Health, InputAttr, InputKind, Inventory,
InventoryAction, Mass, Melee, Ori, PhysicsState, Pos, Scale, SkillSet, Stance, StateUpdate,
Stats, Vel,
Stats, Vel, PreviousPhysCache,
},
link::Is,
mounting::{Rider, VolumeRider},
@ -149,6 +149,7 @@ pub struct JoinData<'a> {
pub mount_data: Option<&'a Is<Rider>>,
pub volume_mount_data: Option<&'a Is<VolumeRider>>,
pub stance: Option<&'a Stance>,
pub previous_physics: Option<&'a PreviousPhysCache>,
}
pub struct JoinStruct<'a> {
@ -179,6 +180,7 @@ pub struct JoinStruct<'a> {
pub mount_data: Option<&'a Is<Rider>>,
pub volume_mount_data: Option<&'a Is<VolumeRider>>,
pub stance: Option<&'a Stance>,
pub previous_physics: Option<&'a PreviousPhysCache>,
}
impl<'a> JoinData<'a> {
@ -223,6 +225,7 @@ impl<'a> JoinData<'a> {
mount_data: j.mount_data,
volume_mount_data: j.volume_mount_data,
stance: j.stance,
previous_physics: j.previous_physics,
}
}
}

View File

@ -146,6 +146,7 @@ impl Body {
quadruped_low::Species::Deadwood => 140.0,
quadruped_low::Species::Mossdrake => 100.0,
},
Body::Ship(ship::Body::Carriage) => 250.0,
Body::Ship(_) => 0.0,
Body::Arthropod(arthropod) => match arthropod.species {
arthropod::Species::Tarantula => 135.0,
@ -220,6 +221,7 @@ impl Body {
quadruped_low::Species::Mossdrake => 1.7,
_ => 2.0,
},
Body::Ship(ship::Body::Carriage) => 0.6,
Body::Ship(ship) if ship.has_water_thrust() => 5.0 / self.dimensions().y,
Body::Ship(_) => 6.0 / self.dimensions().y,
Body::Arthropod(_) => 3.5,
@ -587,6 +589,13 @@ pub fn handle_orientation(
(a.to_quat().into_vec4() - b.to_quat().into_vec4()).reduce(|a, b| a.abs() + b.abs())
}
let pitch = if matches!(data.body, Body::Ship(ship::Body::Carriage)) {
let change = (data.pos.0 - data.previous_physics.and_then(|p| p.pos_interp).unwrap_or(*data.pos).0) / data.dt.0;
change.z / change.xy().magnitude().max(1.0)
} else {
0.0
};
// Direction is set to the override if one is provided, else if entity is
// strafing or attacking the horiontal component of the look direction is used,
// else the current horizontal movement direction is used
@ -601,7 +610,8 @@ pub fn handle_orientation(
} else {
Dir::from_unnormalized(data.inputs.move_dir.into())
.map_or_else(|| to_horizontal_fast(data.ori), |dir| dir.into())
};
}
.pitched_up(pitch);
// unit is multiples of 180°
let half_turns_per_tick = data.body.base_ori_rate() / data.scale.map_or(1.0, |s| s.0.sqrt())
* efficiency

View File

@ -10,7 +10,7 @@ use common::{
inventory::item::{tool::AbilityMap, MaterialStatManifest},
ActiveAbilities, Beam, Body, CharacterActivity, CharacterState, Combo, Controller, Density,
Energy, Health, Inventory, InventoryManip, Mass, Melee, Ori, PhysicsState, Poise, Pos,
Scale, SkillSet, Stance, StateUpdate, Stats, Vel,
Scale, SkillSet, Stance, StateUpdate, Stats, Vel, PreviousPhysCache,
},
event::{EventBus, LocalEvent, ServerEvent},
link::Is,
@ -54,6 +54,7 @@ pub struct ReadData<'a> {
terrain: ReadExpect<'a, TerrainGrid>,
inventories: ReadStorage<'a, Inventory>,
stances: ReadStorage<'a, Stance>,
previous_physics: ReadStorage<'a, PreviousPhysCache>,
}
/// ## Character Behavior System
@ -120,7 +121,7 @@ impl<'a> System<'a> for Sys {
controller,
health,
body,
(physics, scale, stat, skill_set, active_abilities, is_rider),
(physics, scale, stat, skill_set, active_abilities, previous_physics, is_rider),
combo,
) in (
&read_data.entities,
@ -143,6 +144,7 @@ impl<'a> System<'a> for Sys {
&read_data.stats,
&read_data.skill_sets,
read_data.active_abilities.maybe(),
read_data.previous_physics.maybe(),
read_data.is_riders.maybe(),
),
read_data.combos.maybe(),
@ -210,6 +212,7 @@ impl<'a> System<'a> for Sys {
mount_data: read_data.is_riders.get(entity),
volume_mount_data: read_data.is_volume_riders.get(entity),
stance: read_data.stances.get(entity),
previous_physics,
};
for action in actions {

View File

@ -218,6 +218,7 @@ impl<'a> PhysicsData<'a> {
origins: None,
pos: None,
ori: Quaternion::identity(),
pos_interp: None,
});
}
@ -744,6 +745,9 @@ impl<'a> PhysicsData<'a> {
// it did not work (investigate root cause?)
previous_phys_cache.pos = Some(*pos);
previous_phys_cache.ori = ori.to_quat();
previous_phys_cache.pos_interp = Some(Pos(
previous_phys_cache.pos_interp.unwrap_or(*pos).0 * 0.85 + pos.0 * 0.15,
));
}
drop(guard);
}

View File

@ -109,6 +109,7 @@ impl<'a> From<&'a Body> for SkeletonAttr {
Galleon => (0.0, 0.0, 0.0),
Skiff => (0.0, 0.0, 0.0),
Submarine => (0.0, 0.0, 0.0),
Carriage => (0.0, 0.0, 0.0),
Volume => (0.0, 0.0, 0.0),
},
bone1: match body {
@ -118,6 +119,7 @@ impl<'a> From<&'a Body> for SkeletonAttr {
Galleon => (0.0, 0.0, 0.0),
Skiff => (0.0, 0.0, 0.0),
Submarine => (0.0, -15.0, 3.5),
Carriage => (0.0, 0.0, 0.0),
Volume => (0.0, 0.0, 0.0),
},
bone2: match body {
@ -127,6 +129,7 @@ impl<'a> From<&'a Body> for SkeletonAttr {
Galleon => (0.0, 0.0, 0.0),
Skiff => (0.0, 0.0, 0.0),
Submarine => (0.0, 0.0, 0.0),
Carriage => (0.0, 0.0, 0.0),
Volume => (0.0, 0.0, 0.0),
},
bone3: match body {
@ -136,6 +139,7 @@ impl<'a> From<&'a Body> for SkeletonAttr {
Galleon => (0.0, 0.0, 0.0),
Skiff => (0.0, 0.0, 0.0),
Submarine => (0.0, -18.0, 3.5),
Carriage => (0.0, 0.0, 0.0),
Volume => (0.0, 0.0, 0.0),
},
bone1_prop_trail_offset: match body {