Skip to content

Commit

Permalink
Move camera to the top of the player's collider
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralith committed Jan 21, 2024
1 parent bfc92ca commit ba5dcce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 2 additions & 6 deletions client/src/local_character_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<f32> {
Expand Down
12 changes: 11 additions & 1 deletion client/src/sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,17 @@ 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 = 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
Expand Down

0 comments on commit ba5dcce

Please sign in to comment.