generalize lookingat

This commit is contained in:
griffi-gh 2023-01-28 21:37:00 +01:00
parent b8bbda4be8
commit f3e8459968
2 changed files with 4 additions and 5 deletions

View file

@ -34,7 +34,7 @@ use rendering::{
use world::{
init_game_world,
loading::update_loaded_world_around_player,
raycast::update_player_raycast
raycast::update_raycasts
};
use player::spawn_player;
use prefabs::load_prefabs;
@ -64,7 +64,7 @@ fn update() -> Workload {
process_inputs,
update_controllers,
update_loaded_world_around_player,
update_player_raycast,
update_raycasts,
compute_cameras
).into_workload()
}

View file

@ -41,13 +41,12 @@ impl ChunkStorage {
#[derive(Component, Clone, Copy, Debug, Default)]
pub struct LookingAtBlock(pub Option<RaycastReport>);
pub fn update_player_raycast(
main_player: View<MainPlayer>,
pub fn update_raycasts(
transform: View<Transform>,
mut raycast: ViewMut<LookingAtBlock>,
world: UniqueView<ChunkStorage>,
) {
for (_, transform, report) in (&main_player, transform.inserted_or_modified(), &mut raycast).iter() {
for (transform, report) in (transform.inserted_or_modified(), &mut raycast).iter() {
let (_, rotation, position) = transform.0.to_scale_rotation_translation();
let direction = rotation * Vec3::NEG_Z;
*report = LookingAtBlock(world.raycast(position, direction, Some(30.)));