dimforge / dimforge/bevy_rapier
Add `Grounded` marker for `KinematicCharacterController`
- Dominant language
- Rust
- Stars
- 1.6k
- Forks
- 282
- PR merge metrics
- No merged PRs in 30d
Description
A pretty common question I see people ask is "how do I know if my character is grounded?"
This is currently done by querying for the `KinematicCharacterControllerOutput` component and checking the `is_grounded` property.
```rust
fn log_grounded(controllers: Query<(Entity, &KinematicCharacterControllerOutput)>) {
for (entity, output) in &controllers {
println!("Entity {:?} touches the ground: {:?}", entity, output.grounded);
}
}
```
However, in my opinion, a more idiomatic approach would be a `Grounded` marker component. Paired with the `Without` filter, it would make some systems more ergonomic while also reducing the amount of iteration. For example, a simple jumping system could filter out entities that aren't grounded:
```rust
fn jump(
mut jump_event_reader: EventReader,
mut controllers: Query<&mut Velocity, With>,
) {
for event in jump_event_reader.read() {
for (jump_impulse, mut velocity) in &mut controllers {
// A KCC isn't controlled like this, but imagine it works for demonstration purposes.
velocity.linvel.y = event.jump_impulse;
}
}
}
```
For the boolean value, the idiomatic approach is to use `Has`:
```rust
fn log_grounded(controllers: Query<(Entity, Has)>) {
for (entity, is_grounded) in &controllers {
println!("Entity {:?} touches the ground: {:?}", entity, is_grounded);
}
}
```
If desired, the name could also be more specific like `CharacterGrounded` or even `KinematicCharacterGrounded`, but I think just `Grounded` is fine too.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.