diff --git a/rust/src/player/local_player.rs b/rust/src/player/local_player.rs index 4e050cd..915d80f 100644 --- a/rust/src/player/local_player.rs +++ b/rust/src/player/local_player.rs @@ -901,6 +901,7 @@ impl LocalPlayer { camera.get_global_position() + forward, &self.base().get_world_3d(), &Array::from_iter(vec![self.base().get_rid()]), + None, ) { Some(res) => Some(res.position), None => Some(camera.get_global_position() + forward * 100.), diff --git a/rust/src/player/mod.rs b/rust/src/player/mod.rs index 39005c2..29bfbd3 100644 --- a/rust/src/player/mod.rs +++ b/rust/src/player/mod.rs @@ -18,7 +18,7 @@ use crate::{ telegrenade::Telegrenade, weapon::{BallWeapon, Weapon, WeaponType}, }, - util::shotgun_ray, + util::{cast_ray, shotgun_ray}, }; pub mod ball; @@ -110,16 +110,18 @@ impl PlayerCommon for T { self.base_mut().set_velocity(speed); self.base_mut().move_and_slide(); - if let Some(collision) = self.base().get_last_slide_collision() - && let Some(collider) = collision.get_collider() - { - // Detect if it's floor we're contacting with - if collision.get_normal().dot(self.base().get_floor_normal()) > 0.95 { - if let Ok(footstep_box) = collider.try_cast::() { - self.set_walk_kind(footstep_box.bind().kind); - } else { - self.set_walk_kind(FootstepKind::default()); - } + if self.base().is_on_floor() { + if let Some(result) = cast_ray( + self.base().get_global_position() + Vector3::UP, + self.base().get_global_position() + Vector3::DOWN, + &self.base().get_world_3d(), + &Array::new(), + Some(0b100), + ) && let Ok(footstep_box) = result.collider.try_cast::() + { + self.set_walk_kind(footstep_box.bind().kind); + } else { + self.set_walk_kind(FootstepKind::default()); } } } @@ -262,6 +264,7 @@ impl PlayerCommon for T { 10, PI / 2., 2., + None, ); let mut colliders = HashSet::new(); diff --git a/rust/src/player/weapon.rs b/rust/src/player/weapon.rs index 4fa3fd0..3850d19 100644 --- a/rust/src/player/weapon.rs +++ b/rust/src/player/weapon.rs @@ -92,6 +92,7 @@ impl Weapon for Raygun { to, &self.base().get_world_3d(), &Array::from_iter(vec![player]), + None, ); if play_fx { @@ -231,6 +232,7 @@ impl Weapon for Shotgun { 10, PI / 2., 10., + None, ); if play_fx { let mut bullet_decal_results = Vec::new(); diff --git a/rust/src/util.rs b/rust/src/util.rs index 6b0fdcf..d5721c2 100644 --- a/rust/src/util.rs +++ b/rust/src/util.rs @@ -8,10 +8,11 @@ pub fn cast_ray( to: Vector3, world: &Option>, exclude: &Array, + mask: Option, ) -> Option { let ray = PhysicsRayQueryParameters3D::create(from, to); if let Some(mut ray) = ray { - ray.set_collision_mask(0b1111); + ray.set_collision_mask(mask.unwrap_or(0b1111)); ray.set_hit_back_faces(false); ray.set_hit_from_inside(false); ray.set_collide_with_bodies(true); @@ -49,6 +50,7 @@ pub fn shotgun_ray( density: u8, angle: f32, distance: f32, + mask: Option, ) -> Vec { let mut results = Vec::new(); @@ -64,7 +66,7 @@ pub fn shotgun_ray( let x_rot = -(angle / 2.) + step * x as f32; let dir = original_dir.rotated(up, x_rot).rotated(right, y_rot); let to = from + dir * distance; - if let Some(res) = cast_ray(from, to, world, exclude) { + if let Some(res) = cast_ray(from, to, world, exclude, mask) { results.push(res); } }