fix "want to look at player" for when player rides a vehicle

This commit is contained in:
yuni 2024-05-23 00:56:12 +02:00
parent c9e38c7b29
commit e9afeefb7d
3 changed files with 22 additions and 8 deletions

View file

@ -566,13 +566,26 @@ fn handle_wants_lookat(
&mut ExternalTorque, &mut ExternalTorque,
&WantsToLookAt, &WantsToLookAt,
)>, )>,
q_playercam: Query<&Position, With<PlayerCamera>>,
id2pos: Res<game::Id2Pos>, id2pos: Res<game::Id2Pos>,
) { ) {
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 { for (pos, mut rot, mut _torque, target_id) in &mut query {
if let Some(target_pos) = id2pos.0.get(&target_id.0) { 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); rot.0 = look_at_quat(**pos, *target_pos, DVec3::Y);
} }
}
} }
fn handle_damage( fn handle_damage(

View file

@ -18,6 +18,7 @@ use bevy_xpbd_3d::prelude::*;
use regex::Regex; use regex::Regex;
use std::time::SystemTime; use std::time::SystemTime;
pub const ID_SPECIAL_PLAYERCAM: &str = "PLAYERCAMERA";
pub const ID_EARTH: &str = "earth"; pub const ID_EARTH: &str = "earth";
pub const ID_SOL: &str = "sol"; pub const ID_SOL: &str = "sol";
pub const ID_JUPITER: &str = "jupiter"; pub const ID_JUPITER: &str = "jupiter";

View file

@ -462,7 +462,7 @@ actor -3300 10 0 pizzeria
angularmomentum 0 0 0 angularmomentum 0 0 0
wants maxrotation 0 wants maxrotation 0
wants maxvelocity 0 wants maxvelocity 0
wants lookat player wants lookat PLAYERCAMERA
thrust 15 6 3 400 0.5 thrust 15 6 3 400 0.5
rotationy -126 rotationy -126
scale 3 scale 3
@ -479,7 +479,7 @@ actor -3300 10 0 pizzeria
thrust 1.2 1 1 20 1.5 thrust 1.2 1 1 20 1.5
wants maxrotation 0 wants maxrotation 0
wants maxvelocity 0 wants maxvelocity 0
wants lookat player wants lookat PLAYERCAMERA
rotationy -90 rotationy -90
angularmomentum 0 0 0 angularmomentum 0 0 0
pronoun he pronoun he
@ -538,7 +538,7 @@ actor 100 -18000 2000 clippy
angularmomentum 0 0 0 angularmomentum 0 0 0
wants maxrotation 0 wants maxrotation 0
wants maxvelocity 0 wants maxvelocity 0
wants lookat player wants lookat PLAYERCAMERA
thrust 15 6 3 400 0.5 thrust 15 6 3 400 0.5
pointofinterest yes pointofinterest yes
rotationy -90 rotationy -90
@ -690,7 +690,7 @@ actor -184971e3 149410e3 -134273e3 clippy
angularmomentum 0 0 0 angularmomentum 0 0 0
wants maxrotation 0 wants maxrotation 0
wants maxvelocity 0 wants maxvelocity 0
wants lookat player wants lookat PLAYERCAMERA
thrust 15 6 3 400 0.5 thrust 15 6 3 400 0.5
pointofinterest yes pointofinterest yes
rotationy -90 rotationy -90
@ -835,7 +835,7 @@ actor 0 -44e3 0 clippy
angularmomentum 0 0 0 angularmomentum 0 0 0
wants maxrotation 0 wants maxrotation 0
wants maxvelocity 0 wants maxvelocity 0
wants lookat player wants lookat PLAYERCAMERA
thrust 15 6 3 400 0.5 thrust 15 6 3 400 0.5
pointofinterest yes pointofinterest yes
rotationy -90 rotationy -90