You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
fnlog_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:
fnjump(mutjump_event_reader:EventReader<JumpEvent>,mutcontrollers:Query<&mutVelocity,With<Grounded>>,){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:
fnlog_grounded(controllers:Query<(Entity,Has<Grounded>)>){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.
The text was updated successfully, but these errors were encountered:
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 theis_grounded
property.However, in my opinion, a more idiomatic approach would be a
Grounded
marker component. Paired with theWithout
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:For the boolean value, the idiomatic approach is to use
Has
:If desired, the name could also be more specific like
CharacterGrounded
or evenKinematicCharacterGrounded
, but I think justGrounded
is fine too.The text was updated successfully, but these errors were encountered: