From e9afeefb7db47950b88cac445880be442d3d59df Mon Sep 17 00:00:00 2001 From: yuni Date: Thu, 23 May 2024 00:56:12 +0200 Subject: [PATCH] fix "want to look at player" for when player rides a vehicle --- src/actor.rs | 19 ++++++++++++++++--- src/cmd.rs | 1 + src/data/defs.txt | 10 +++++----- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/actor.rs b/src/actor.rs index 1ca5657..d3738ce 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -566,12 +566,25 @@ fn handle_wants_lookat( &mut ExternalTorque, &WantsToLookAt, )>, + q_playercam: Query<&Position, With>, id2pos: Res, ) { + let player_pos = if let Ok(player_pos) = q_playercam.get_single() { + player_pos + } else { + error!("Can't find player position"); + return; + }; + for (pos, mut rot, mut _torque, target_id) in &mut query { - if let Some(target_pos) = id2pos.0.get(&target_id.0) { - rot.0 = look_at_quat(**pos, *target_pos, DVec3::Y); - } + let target_pos = if target_id.0 == cmd::ID_SPECIAL_PLAYERCAM { + player_pos + } else if let Some(target_pos) = id2pos.0.get(&target_id.0) { + target_pos + } else { + continue; + }; + rot.0 = look_at_quat(**pos, *target_pos, DVec3::Y); } } diff --git a/src/cmd.rs b/src/cmd.rs index c8546c8..f896505 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -18,6 +18,7 @@ use bevy_xpbd_3d::prelude::*; use regex::Regex; use std::time::SystemTime; +pub const ID_SPECIAL_PLAYERCAM: &str = "PLAYERCAMERA"; pub const ID_EARTH: &str = "earth"; pub const ID_SOL: &str = "sol"; pub const ID_JUPITER: &str = "jupiter"; diff --git a/src/data/defs.txt b/src/data/defs.txt index 89e661d..8344bce 100644 --- a/src/data/defs.txt +++ b/src/data/defs.txt @@ -462,7 +462,7 @@ actor -3300 10 0 pizzeria angularmomentum 0 0 0 wants maxrotation 0 wants maxvelocity 0 - wants lookat player + wants lookat PLAYERCAMERA thrust 15 6 3 400 0.5 rotationy -126 scale 3 @@ -479,7 +479,7 @@ actor -3300 10 0 pizzeria thrust 1.2 1 1 20 1.5 wants maxrotation 0 wants maxvelocity 0 - wants lookat player + wants lookat PLAYERCAMERA rotationy -90 angularmomentum 0 0 0 pronoun he @@ -538,7 +538,7 @@ actor 100 -18000 2000 clippy angularmomentum 0 0 0 wants maxrotation 0 wants maxvelocity 0 - wants lookat player + wants lookat PLAYERCAMERA thrust 15 6 3 400 0.5 pointofinterest yes rotationy -90 @@ -690,7 +690,7 @@ actor -184971e3 149410e3 -134273e3 clippy angularmomentum 0 0 0 wants maxrotation 0 wants maxvelocity 0 - wants lookat player + wants lookat PLAYERCAMERA thrust 15 6 3 400 0.5 pointofinterest yes rotationy -90 @@ -835,7 +835,7 @@ actor 0 -44e3 0 clippy angularmomentum 0 0 0 wants maxrotation 0 wants maxvelocity 0 - wants lookat player + wants lookat PLAYERCAMERA thrust 15 6 3 400 0.5 pointofinterest yes rotationy -90