Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
janhohenheim committed Aug 31, 2024
1 parent f322f80 commit 8c54fe4
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/third_party_setup/avian/collision_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,22 @@ pub(super) fn plugin(app: &mut App) {

#[derive(PhysicsLayer, Default)]
pub enum CollisionLayer {
/// Any [`RigidBody::Static`] collider that does not have an explicit layer will default to `Terrain`.
/// This is used for e.g. the ground, trees, benches, buildings, etc.
#[default]
Terrain,
Player,
/// A character is any entity that can move around and interact with the environment.
Character,
/// The player character.
Player,
/// A prop is a [`RigidBody::Dynamic`] collider, i.e. it can be influenced by physics.
Prop,
/// A [`Sensor`] that detects the presence of a player in order to allow the player to initiate dialogue.
DialogSensor,
}

/// A way to easily override the default collision layer in Blender.
/// Does not include `Terrain` because that one is already the default.
#[derive(Debug, Clone, Copy, Reflect, PartialEq, Eq)]
#[reflect(Debug, PartialEq, Component)]
pub enum CollisionLayerPreset {
Expand All @@ -31,15 +39,18 @@ impl From<CollisionLayerPreset> for CollisionLayers {
fn from(preset: CollisionLayerPreset) -> Self {
use CollisionLayer::*;
match preset {
// A player is both a character and a player. They can interact pretty much everything.
CollisionLayerPreset::Player => CollisionLayers::new(
[Player, Character],
[Terrain, Character, Prop, DialogSensor],
),
// NPCs are just characters. They cannot interact with sensors in this case.
CollisionLayerPreset::Npc => {
CollisionLayers::new([Character], [Terrain, Character, Prop])
}
// Since in our example our only sen
// Dialog sensors can only interact with players.
CollisionLayerPreset::DialogSensor => CollisionLayers::new(DialogSensor, Player),
// Props can interact with terrain, other props, and characters.
CollisionLayerPreset::Prop => CollisionLayers::new(Prop, [Terrain, Prop, Character]),
}
}
Expand Down

0 comments on commit 8c54fe4

Please sign in to comment.