From 08b46f5ca62b062d24e883a35ff1f8a796d57680 Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Sat, 20 Jan 2024 18:38:22 -0800 Subject: [PATCH] Move camera to the top of the player's collider --- client/src/local_character_controller.rs | 8 ++------ client/src/sim.rs | 10 +++++++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/client/src/local_character_controller.rs b/client/src/local_character_controller.rs index a4197d7a..ef55dd41 100644 --- a/client/src/local_character_controller.rs +++ b/client/src/local_character_controller.rs @@ -21,12 +21,8 @@ impl LocalCharacterController { } } - /// Get the current position with orientation applied to it - pub fn oriented_position(&self) -> Position { - Position { - node: self.position.node, - local: self.position.local * self.orientation.to_homogeneous(), - } + pub fn position(&self) -> Position { + self.position } pub fn orientation(&self) -> na::UnitQuaternion { diff --git a/client/src/sim.rs b/client/src/sim.rs index 9498734e..b3139346 100644 --- a/client/src/sim.rs +++ b/client/src/sim.rs @@ -437,7 +437,15 @@ impl Sim { } pub fn view(&self) -> Position { - self.local_character_controller.oriented_position() + let mut pos = self.local_character_controller.position(); + let up = self.graph.get_relative_up(&pos).unwrap(); + pos.local *= common::math::translate_along( + &(up.as_ref() * (self.cfg.character.character_radius - 1e-3)), + ) * self + .local_character_controller + .orientation() + .to_homogeneous(); + pos } /// Destroy all aspects of an entity