pub fn character_grounded_system(
    qp: Res<QueryPipeline>,
    mut rigidbodies: ResMut<RigidBodySet>,
    colliders: Res<ColliderSet>,
    mut query: Query<(&mut Character, &Sprite, &RigidBodyHandleComponent)>,
) {
    for (mut character, sprite, rbhandle) in query.iter_mut() {
        if let Some(rigidbody) = rigidbodies.get_mut(rbhandle.handle()) {
            let half_height = sprite.size.y / 2.0;

            let position = rigidbody.position();

            let ray = Ray::new(
                Point::new(position.translation.x, position.translation.y - half_height),
                Vector::y() * -1.0,
            );

            if let Some((_handle, _collider)) = qp.cast_ray(
                &colliders,
                &ray,
                0.1,
                true,
                *CHARACTER_COLLISION_GROUPS,
                None,
            ) {
                character.grounded = true;
            } else {
                character.grounded = false;
            }
        }
    }
}
/// Checks whether a character is on the ground or not
Checks whether a character is on the ground or not
Checks whether a character is on the ground or not
pub fn character_grounded_system(
    qp: Res<QueryPipeline>,
    mut rigidbodies: ResMut<RigidBodySet>,
    colliders: Res<ColliderSet>,
    mut query: Query<(&mut Character, &Sprite, &RigidBodyHandleComponent)>,
) {
    for (mut character, sprite, rbhandle) in query.iter_mut() {
        if let Some(rigidbody) = rigidbodies.get_mut(rbhandle.handle()) {
            let half_height = sprite.size.y / 2.0;
            let position = rigidbody.position();
            let ray = Ray::new(
                Point::new(position.translation.x, position.translation.y - half_height),
                Vector::y() * -1.0,
            );
            if let Some((_handle, _collider)) = qp.cast_ray(
                &colliders,
                &ray,
                0.1,
                true,
                *CHARACTER_COLLISION_GROUPS,
                None,
            ) {
                character.grounded = true;
            } else {
                character.grounded = false;
            }
        }
    }
}
pub fn character_grounded_system ( qp : Res < QueryPipeline > , mut rigidbodies : ResMut < RigidBodySet > , colliders : Res < ColliderSet > , mut query : Query < ( & mut Character , & Sprite , & RigidBodyHandleComponent ) > , ) { for ( mut character , sprite , rbhandle ) in query . iter_mut ( ) { if let Some ( rigidbody ) = rigidbodies . get_mut ( rbhandle . handle ( ) ) { let half_height = sprite . size . y / 2.0 ; let position = rigidbody . position ( ) ; let ray = Ray :: new ( Point :: new ( position . translation . x , position . translation . y - half_height ) , Vector :: y ( ) * - 1.0 , ) ; if let Some ( ( _handle , _collider ) ) = qp . cast_ray ( & colliders , & ray , 0.1 , true , * CHARACTER_COLLISION_GROUPS , None , ) { character . grounded = true ; } else { character . grounded = false ; } } } }
Checks whether a character is on the ground or not
Checks whether a character is on the ground or not
qp
Res<QueryPipeline>
rigidbodies
ResMut<RigidBodySet>
colliders
Res<ColliderSet>
query
Query<(&mut Character, &Sprite, &RigidBodyHandleComponent)>
qp
Res<QueryPipeline>
rigidbodies
ResMut<RigidBodySet>
colliders
Res<ColliderSet>
query
Query<(&mut Character, &Sprite, &RigidBodyHandleComponent)>