entering vehicles now also based on camera orientation
This commit is contained in:
parent
f13fc7167d
commit
845e938472
18
src/actor.rs
18
src/actor.rs
|
@ -208,9 +208,9 @@ pub fn handle_input(
|
|||
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||
settings: ResMut<settings::Settings>,
|
||||
q_talker: Query<(&chat::Talker, &Transform), (Without<actor::Player>, Without<Camera>)>,
|
||||
mut player: Query<(Entity, &mut Transform), (With<actor::Player>, Without<Camera>)>,
|
||||
player: Query<Entity, With<actor::Player>>,
|
||||
q_camera: Query<&Transform, With<Camera>>,
|
||||
mut q_vehicles: Query<(Entity, &mut Visibility, &Transform), (With<actor::Vehicle>, Without<actor::Player>, Without<Camera>)>,
|
||||
q_vehicles: Query<(Entity, &Transform), (With<actor::Vehicle>, Without<actor::Player>, Without<Camera>)>,
|
||||
mut ew_conv: EventWriter<chat::StartConversationEvent>,
|
||||
mut ew_vehicle: EventWriter<VehicleEnterExitEvent>,
|
||||
q_player_drives: Query<Entity, With<PlayerDrivesThis>>,
|
||||
|
@ -219,7 +219,7 @@ pub fn handle_input(
|
|||
return;
|
||||
}
|
||||
let camtrans = q_camera.get_single().unwrap();
|
||||
let (player_entity, player) = player.get_single().unwrap();
|
||||
let player_entity = player.get_single().unwrap();
|
||||
|
||||
if keyboard_input.just_pressed(settings.key_interact) {
|
||||
// Talking to people
|
||||
|
@ -235,17 +235,19 @@ pub fn handle_input(
|
|||
}
|
||||
// Entering Vehicles
|
||||
if q_player_drives.is_empty() {
|
||||
for (vehicle_entity, _visibility, vehicle_transform) in q_vehicles.iter_mut() {
|
||||
if vehicle_transform.translation.distance_squared(player.translation) <= MAX_INTERACT_DISTANCE * MAX_INTERACT_DISTANCE {
|
||||
commands.entity(vehicle_entity).insert(ActorVehicleBeingEntered);
|
||||
let objects: Vec<(Entity, &Transform)> = q_vehicles
|
||||
.iter()
|
||||
.collect();
|
||||
if let (Some(entity), dist) = camera::find_closest_target::<Entity>(objects, camtrans) {
|
||||
if dist <= MAX_INTERACT_DISTANCE {
|
||||
commands.entity(entity).insert(ActorVehicleBeingEntered);
|
||||
commands.entity(player_entity).insert(ActorEnteringVehicle);
|
||||
ew_vehicle.send(VehicleEnterExitEvent{
|
||||
vehicle: vehicle_entity,
|
||||
vehicle: entity,
|
||||
driver: player_entity,
|
||||
is_entering: q_player_drives.is_empty(),
|
||||
is_player: true,
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue