From b086b43a88fbe019437232b44929a9ebd81bd086 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Thu, 25 May 2023 00:16:35 +0100 Subject: [PATCH] Better wheeled ship movement --- common/src/comp/body/ship.rs | 4 ++-- common/src/comp/phys.rs | 2 +- common/src/states/behavior.rs | 7 ++----- common/src/states/utils.rs | 3 ++- common/systems/src/character_behavior.rs | 7 ++----- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/common/src/comp/body/ship.rs b/common/src/comp/body/ship.rs index f0ba0470d3..428a18124a 100644 --- a/common/src/comp/body/ship.rs +++ b/common/src/comp/body/ship.rs @@ -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) } diff --git a/common/src/comp/phys.rs b/common/src/comp/phys.rs index 31282be1f9..2b21bf543f 100644 --- a/common/src/comp/phys.rs +++ b/common/src/comp/phys.rs @@ -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), } diff --git a/common/src/states/behavior.rs b/common/src/states/behavior.rs index e2225dbb45..8bc65b4030 100644 --- a/common/src/states/behavior.rs +++ b/common/src/states/behavior.rs @@ -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>, pub volume_mount_data: Option<&'a Is>, 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>, pub volume_mount_data: Option<&'a Is>, 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, } } } diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index d2d8e4afce..ec9579bcf0 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -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; diff --git a/common/systems/src/character_behavior.rs b/common/systems/src/character_behavior.rs index b6d8c1a392..59099305b7 100644 --- a/common/systems/src/character_behavior.rs +++ b/common/systems/src/character_behavior.rs @@ -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 {