-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6dcdf64
commit 2213aa6
Showing
21 changed files
with
98 additions
and
16 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use bevy::prelude::{App, Entity, Plugin, Resource, Res, Update, IntoSystemConfigs, in_state, Transform, Query, Camera, Vec3, Without}; | ||
|
||
use crate::{selection::{SelectedEntity, apply_camera_to_selection}, SimState, body::{BodyChildren, Mass}, pan_orbit::lib::pan_orbit_camera, physics::update_position}; | ||
|
||
pub struct LockOnPlugin; | ||
|
||
impl Plugin for LockOnPlugin { | ||
|
||
fn build(&self, app: &mut App) { | ||
app | ||
.init_resource::<LockOn>() | ||
.add_systems(Update, (lock_on.after(update_position)).run_if(in_state(SimState::Simulation))); | ||
} | ||
|
||
} | ||
|
||
#[derive(Resource, Default)] | ||
pub struct LockOn(pub bool); | ||
|
||
fn lock_on( | ||
lock_on: Res<LockOn>, | ||
mut query: Query<(Entity, &Transform, Option<&BodyChildren>, Without<Camera>)>, | ||
mut camera: Query<(&Camera, &mut Transform, Without<Mass>, Without<BodyChildren>)>, | ||
selected_entity: Res<SelectedEntity> | ||
) { | ||
if !lock_on.0 { | ||
return; | ||
} | ||
if let Some(s_entity) = selected_entity.0 { | ||
let mut parent: Option<&Transform> = None; | ||
let mut selected: Option<&Transform> = None; | ||
for (entity, transform, children, _) in query.iter_mut() { | ||
if let Some(children) = children { | ||
if children.0.contains(&s_entity) { | ||
parent = Some(transform); | ||
} | ||
} | ||
if s_entity == entity { | ||
selected = Some(transform); | ||
} | ||
} | ||
if let Some(p_transform) = parent { | ||
if let Some(s_transform) = selected { | ||
let (_, mut c_transform, _, _) = camera.single_mut(); | ||
c_transform.look_at(p_transform.translation, Vec3::Y); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters