@@ -640,4 +640,63 @@ mod test {
640640 }
641641 }
642642 }
643+
644+ #[ test]
645+ fn parent_child ( ) {
646+ return main ( ) ;
647+
648+ use bevy:: prelude:: * ;
649+
650+ fn main ( ) {
651+ let mut app = App :: new ( ) ;
652+ app. add_plugins ( (
653+ TransformPlugin ,
654+ TimePlugin ,
655+ RapierPhysicsPlugin :: < NoUserData > :: default ( ) . in_fixed_schedule ( ) ,
656+ ) ) ;
657+ run_test ( & mut app) ;
658+ }
659+
660+ fn run_test ( app : & mut App ) {
661+ app. insert_resource ( TimeUpdateStrategy :: ManualDuration (
662+ std:: time:: Duration :: from_secs_f32 ( 1f32 / 60f32 ) ,
663+ ) ) ;
664+ app. add_systems ( Startup , init_rapier_configuration) ;
665+ app. add_systems ( Startup , setup_physics) ;
666+
667+ app. finish ( ) ;
668+ for _ in 0 ..100 {
669+ app. update ( ) ;
670+ }
671+ let context = app
672+ . world_mut ( )
673+ . query :: < RapierContext > ( )
674+ . get_single ( & app. world ( ) )
675+ . unwrap ( ) ;
676+
677+ println ! ( "{:#?}" , & context. rigidbody_set. bodies) ;
678+ }
679+
680+ pub fn init_rapier_configuration (
681+ mut config : Query < & mut RapierConfiguration , With < DefaultRapierContext > > ,
682+ ) {
683+ let mut config = config. single_mut ( ) ;
684+ * config = RapierConfiguration {
685+ force_update_from_transform_changes : true ,
686+ ..RapierConfiguration :: new ( 1f32 )
687+ } ;
688+ }
689+
690+ pub fn setup_physics ( mut commands : Commands ) {
691+ let parent = commands
692+ . spawn ( Transform :: from_scale ( Vec3 :: splat ( 5f32 ) ) )
693+ . id ( ) ;
694+ let mut entity = commands. spawn ( (
695+ Collider :: ball ( 1f32 ) ,
696+ Transform :: from_translation ( Vec3 :: new ( 200f32 , 100f32 , 3f32 ) ) ,
697+ RigidBody :: Fixed ,
698+ ) ) ;
699+ entity. set_parent ( parent) ;
700+ }
701+ }
643702}
0 commit comments