mgecumshooter/esotera
implemented primitive step height
Commit 474f9531caba · mgecumshooter · 2026-10-24 12:39 +0300
Comments
No comments yet.
Diff
diff --git a/src/player/mod.rs b/src/player/mod.rs
--- a/src/player/mod.rs
+++ b/src/player/mod.rs
@@ -3,7 +3,8 @@
use crate::util::*;
use crate::voxel::*;
-use crate::chunk::Chunk;
+use crate::chunk::{Chunk, *};
+use crate::world::*;
const MOVE_SPEED: f32 = 10f32;
const MOUSE_SENS: f32 = 0.05f32;
@@ -11,6 +12,7 @@
const GRAVITY: f32 = 15f32;
const TERMINAL_GRAVITY: f32 = 40f32;
+#[derive(Clone, Copy)]
pub enum Axis {
X,
Y,
@@ -107,6 +109,35 @@
hit
}
+
+ fn move_horizontal(&mut self, velocity: f32, axis: Axis, world: &Vec<Aabb>) {
+ let before = self.pos;
+ const STEP_HEIGHT: f32 = 1f32;
+
+ if !self.move_axis(velocity, axis, world) {
+ return;
+ }
+
+ self.pos = before;
+ self.pos.y += STEP_HEIGHT;
+
+ if self.check_collision(world) {
+ self.pos = before;
+ self.move_axis(velocity, axis, world);
+ return;
+ }
+
+ if self.move_axis(velocity, axis, world) {
+ self.pos = before;
+ self.move_axis(velocity, axis, world);
+ }
+ }
+
+ fn check_collision(&self, world: &Vec<Aabb>) -> bool {
+ let plr = self.get_aabb();
+ world.iter().any(|voxel| plr.overlaps(voxel))
+ }
+
pub fn get_surroundings(&self, world: &[&Chunk]) -> Vec<Aabb> {
let plr_aabb = self.get_aabb();
let mut obstacles = Vec::new();
@@ -180,8 +211,8 @@
let obstacles = self.get_surroundings(world);
let dt = rl.get_frame_time();
- self.move_axis(wish.x * MOVE_SPEED * dt, Axis::X, &obstacles);
- self.move_axis(wish.z * MOVE_SPEED * dt, Axis::Z, &obstacles);
+ self.move_horizontal(wish.x * MOVE_SPEED * dt, Axis::X, &obstacles);
+ self.move_horizontal(wish.z * MOVE_SPEED * dt, Axis::Z, &obstacles);
self.vel_y = (self.vel_y - GRAVITY * dt).min(TERMINAL_GRAVITY);
if self.move_axis(self.vel_y * dt, Axis::Y, &obstacles) {