-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Outlines #267
base: act-2-bevy
Are you sure you want to change the base?
feat: Outlines #267
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ use bevy::input::common_conditions::input_just_pressed; | |
use bevy::log::LogPlugin; | ||
use bevy::prelude::*; | ||
use bevy::winit::WinitWindows; | ||
use bevy_edge_detection::EdgeDetectionPlugin; | ||
use bevy_mod_outline::OutlinePlugin; | ||
use bevy_rapier3d::prelude::*; | ||
use winit::window::Icon; | ||
|
||
|
@@ -58,20 +60,22 @@ fn main() { | |
}, | ||
}) | ||
.set(LogPlugin { | ||
filter: "info,sbepis=debug,avian3d=debug,wgpu=error,naga=warn,calloop=error,symphonia_core=warn,symphonia_bundle_mp3=warn,blenvy=error".into(), | ||
filter: "info,sbepis=debug,avian3d=debug,wgpu=error,naga=warn,calloop=error,symphonia_core=warn,symphonia_bundle_mp3=warn,blenvy=error,bevy_mod_outline=error".into(), | ||
..default() | ||
}), | ||
RapierPhysicsPlugin::<NoUserData>::default(), | ||
#[cfg(feature = "rapier_debug")] | ||
RapierDebugRenderPlugin::default(), | ||
#[cfg(feature = "inspector")] | ||
bevy_inspector_egui::quick::WorldInspectorPlugin::new(), | ||
#[cfg(feature = "overview_camera")] | ||
overview_camera::OverviewCameraPlugin, | ||
bevy_hanabi::HanabiPlugin, | ||
OutlinePlugin, | ||
)); | ||
|
||
app.add_plugins(( | ||
#[cfg(feature = "rapier_debug")] | ||
RapierDebugRenderPlugin::default(), | ||
#[cfg(feature = "inspector")] | ||
bevy_inspector_egui::quick::WorldInspectorPlugin::new(), | ||
#[cfg(feature = "overview_camera")] | ||
overview_camera::OverviewCameraPlugin, | ||
EdgeDetectionPlugin::default(), | ||
RapierPhysicsPlugin::<NoUserData>::default(), | ||
bevy_hanabi::HanabiPlugin, | ||
Comment on lines
+70
to
+78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had these set up in the above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah this doesn't even compile There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it does for me, I will fix this, I know what I changed. |
||
player_commands::PlayerCommandsPlugin, | ||
camera::PlayerCameraPlugin, | ||
skybox::SkyboxPlugin, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ use crate::entity::{Healing, RandomInput, RotateTowardMovement, SpawnHealthBar}; | |
use crate::gridbox_material; | ||
use crate::main_bundles::Mob; | ||
use crate::npcs::NpcPlugin; | ||
use crate::player_controller::camera_controls::InteractOutlineComponentTarget; | ||
use crate::questing::{QuestGiver, SpawnQuestMarker}; | ||
|
||
use super::name_tags::SpawnNameTag; | ||
|
@@ -39,36 +40,44 @@ fn spawn_consort( | |
continue; | ||
} | ||
|
||
commands.entity(ev.entity).insert(( | ||
Name::new("Consort"), | ||
Transform::from_translation(ev.position), | ||
Mob, | ||
SpawnHealthBar, | ||
RandomInput::default(), | ||
Healing(0.2), | ||
RotateTowardMovement, | ||
Consort, | ||
QuestGiver::default(), | ||
SpawnQuestMarker, | ||
SpawnNameTag, | ||
)); | ||
let mut id = None; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a way better way to get child Entities. Just call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice! |
||
commands.entity(ev.entity).with_children(|parent| { | ||
id = Some( | ||
parent | ||
.spawn(( | ||
Transform::from_translation(Vec3::Y * 0.5), | ||
Mesh3d( | ||
meshes.add( | ||
Capsule3d::new(0.25, 0.5) | ||
.mesh() | ||
.rings(1) | ||
.latitudes(8) | ||
.longitudes(16) | ||
.uv_profile(CapsuleUvProfile::Fixed), | ||
), | ||
), | ||
MeshMaterial3d(gridbox_material("magenta", &mut materials, &asset_server)), | ||
Collider::capsule_y(0.25, 0.25), | ||
)) | ||
.id(), | ||
); | ||
}); | ||
commands | ||
.entity(ev.entity) | ||
.insert(( | ||
Name::new("Consort"), | ||
Transform::from_translation(ev.position), | ||
Mob, | ||
SpawnHealthBar, | ||
RandomInput::default(), | ||
Healing(0.2), | ||
RotateTowardMovement, | ||
Consort, | ||
QuestGiver::default(), | ||
SpawnQuestMarker, | ||
SpawnNameTag, | ||
)) | ||
.with_child(( | ||
Transform::from_translation(Vec3::Y * 0.5), | ||
Mesh3d( | ||
meshes.add( | ||
Capsule3d::new(0.25, 0.5) | ||
.mesh() | ||
.rings(1) | ||
.latitudes(8) | ||
.longitudes(16) | ||
.uv_profile(CapsuleUvProfile::Fixed), | ||
), | ||
), | ||
MeshMaterial3d(gridbox_material("magenta", &mut materials, &asset_server)), | ||
Collider::capsule_y(0.25, 0.25), | ||
)); | ||
.insert(InteractOutlineComponentTarget(id.unwrap())); | ||
ev_spawned.send(EntitySpawned(ev.entity)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ use std::marker::PhantomData; | |
|
||
use bevy::prelude::*; | ||
use bevy_butler::*; | ||
use bevy_mod_outline::OutlineVolume; | ||
use bevy_rapier3d::prelude::*; | ||
use leafwing_input_manager::prelude::*; | ||
|
||
|
@@ -64,21 +65,24 @@ fn rotate_camera_and_body( | |
} | ||
} | ||
|
||
#[resource(plugin = PlayerControllerPlugin, init = LastHitEntity(None))] | ||
#[derive(Resource)] | ||
pub struct LastHitEntity(pub Option<Entity>); | ||
|
||
#[derive(Component)] | ||
pub struct InteractOutlineComponentTarget(pub Entity); | ||
|
||
pub fn interact_with<T: Component>( | ||
rapier_context: Query<&RapierContext>, | ||
player_camera: Query<&GlobalTransform, With<PlayerCamera>>, | ||
entities: Query<Entity, With<T>>, | ||
parents: Query<&Parent>, | ||
input: Query<&ActionState<PlayerAction>>, | ||
outline_targets: Query<&InteractOutlineComponentTarget>, | ||
mut commands: Commands, | ||
mut last_hit: ResMut<LastHitEntity>, | ||
mut ev_interact: EventWriter<InteractedWith<T>>, | ||
) { | ||
if !match input.iter().find(|input| !input.disabled()) { | ||
Some(input) => input.just_pressed(&PlayerAction::Interact), | ||
None => false, | ||
} { | ||
return; | ||
} | ||
|
||
let player_camera = player_camera.get_single().expect("Player camera missing"); | ||
let mut hit_entity: Option<(Option<Entity>, f32)> = None; | ||
rapier_context.single().intersections_with_ray( | ||
|
@@ -102,6 +106,52 @@ pub fn interact_with<T: Component>( | |
}, | ||
); | ||
|
||
if let Some((Some(entity), _)) = hit_entity { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW there is some flickering in the selection here.... any ideas why? I'll have to debug this sooner or later.... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its only every other time I run the game too which sucks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did see that, I have NO idea-- oh wait it's probably system run order race condition stuff. run the shader system |
||
if last_hit.0.is_none() { | ||
for target in outline_targets.get(entity).iter() { | ||
commands.entity(target.0).insert(OutlineVolume { | ||
colour: Color::Srgba(Srgba { | ||
red: 1.0, | ||
green: 1.0, | ||
blue: 1.0, | ||
alpha: 1.0, | ||
}), | ||
visible: true, | ||
width: 1.0, | ||
}); | ||
} | ||
} | ||
match last_hit.0 { | ||
None => {} | ||
Some(last_hit_entity) => { | ||
if last_hit_entity != entity { | ||
for target in outline_targets.get(last_hit_entity).iter() { | ||
commands.entity(target.0).remove::<OutlineVolume>(); | ||
} | ||
last_hit.0 = None; | ||
} | ||
} | ||
} | ||
last_hit.0 = Some(entity); | ||
} else { | ||
match last_hit.0 { | ||
None => {} | ||
Some(last_hit_entity) => { | ||
for target in outline_targets.get(last_hit_entity).iter() { | ||
commands.entity(target.0).remove::<OutlineVolume>(); | ||
} | ||
last_hit.0 = None; | ||
} | ||
} | ||
} | ||
|
||
if !match input.iter().find(|input| !input.disabled()) { | ||
Some(input) => input.just_pressed(&PlayerAction::Interact), | ||
None => false, | ||
} { | ||
return; | ||
} | ||
|
||
if let Some((Some(entity), _)) = hit_entity { | ||
ev_interact.send(InteractedWith::new(entity)); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This particular line should not be indented... Do you have cargo fmt and format-on-save?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stuffs broken on windows. cant fix rn, will do
cargo fmt
and commit.