Better wheeled ship movement

This commit is contained in:
Joshua Barretto 2023-05-25 00:16:35 +01:00
parent 8e85ff98a6
commit b086b43a88
5 changed files with 9 additions and 14 deletions

View File

@ -84,7 +84,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),
Body::Carriage => Vec3::new(6.0, 12.0, 8.0),
}
}
@ -133,7 +133,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() && !matches!(self, Body::Carriage) // TODO: Differentiate this more carefully
matches!(self, Body::SailBoat | Body::Galleon | Body::Skiff)
}
pub fn has_wheels(&self) -> bool { matches!(self, Body::Carriage) }

View File

@ -153,7 +153,7 @@ impl Collider {
pub fn get_z_limits(&self, modifier: f32) -> (f32, f32) {
match self {
Collider::Voxel { .. } | Collider::Volume(_) => (0.0, 1.0),
Collider::Voxel { .. } | Collider::Volume(_) => (0.0, 2.0),
Collider::CapsulePrism { z_min, z_max, .. } => (*z_min * modifier, *z_max * modifier),
Collider::Point => (0.0, 0.0),
}

View File

@ -5,8 +5,8 @@ use crate::{
item::{tool::AbilityMap, MaterialStatManifest},
ActiveAbilities, Beam, Body, CharacterActivity, CharacterState, Combo, ControlAction,
Controller, ControllerInputs, Density, Energy, Health, InputAttr, InputKind, Inventory,
InventoryAction, Mass, Melee, Ori, PhysicsState, Pos, PreviousPhysCache, Scale, SkillSet,
Stance, StateUpdate, Stats, Vel,
InventoryAction, Mass, Melee, Ori, PhysicsState, Pos, Scale, SkillSet, Stance, StateUpdate,
Stats, Vel,
},
link::Is,
mounting::{Rider, VolumeRider},
@ -149,7 +149,6 @@ 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> {
@ -180,7 +179,6 @@ 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> {
@ -225,7 +223,6 @@ 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

@ -589,7 +589,7 @@ pub fn handle_orientation(
(a.to_quat().into_vec4() - b.to_quat().into_vec4()).reduce(|a, b| a.abs() + b.abs())
}
let (tilt_ori, efficiency) = if let Body::Ship(ship) = data.body && ship.has_wheels() && data.physics.on_ground.is_some() {
let (tilt_ori, efficiency) = if let Body::Ship(ship) = data.body && ship.has_wheels() {
let height_at = |rpos| data
.terrain
.ray(
@ -600,6 +600,7 @@ pub fn handle_orientation(
.cast()
.0;
// Do some cheap raycasting with the ground to determine the appropriate orientation for the vehicle
let x_diff = (height_at(data.ori.to_horizontal().right().to_vec() * 3.0) - height_at(data.ori.to_horizontal().right().to_vec() * -3.0)) / 10.0;
let y_diff = (height_at(data.ori.to_horizontal().look_dir().to_vec() * -4.5) - height_at(data.ori.to_horizontal().look_dir().to_vec() * 4.5)) / 10.0;

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,
PreviousPhysCache, Scale, SkillSet, Stance, StateUpdate, Stats, Vel,
Scale, SkillSet, Stance, StateUpdate, Stats, Vel,
},
event::{EventBus, LocalEvent, ServerEvent},
link::Is,
@ -54,7 +54,6 @@ pub struct ReadData<'a> {
terrain: ReadExpect<'a, TerrainGrid>,
inventories: ReadStorage<'a, Inventory>,
stances: ReadStorage<'a, Stance>,
previous_physics: ReadStorage<'a, PreviousPhysCache>,
}
/// ## Character Behavior System
@ -121,7 +120,7 @@ impl<'a> System<'a> for Sys {
controller,
health,
body,
(physics, scale, stat, skill_set, active_abilities, previous_physics, is_rider),
(physics, scale, stat, skill_set, active_abilities, is_rider),
combo,
) in (
&read_data.entities,
@ -144,7 +143,6 @@ 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(),
@ -212,7 +210,6 @@ 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 {