11use std:: { fs:: File , io:: Write } ;
22
3- use bevy:: prelude:: * ;
3+ use bevy:: { color :: palettes , prelude:: * } ;
44use bevy_mod_debugdump:: { schedule_graph, schedule_graph_dot} ;
55use bevy_rapier2d:: prelude:: * ;
6- use bevy_transform_interpolation:: {
6+ use bevy_transform_interpolation:: prelude :: {
77 RotationInterpolation , TransformInterpolationPlugin , TranslationInterpolation ,
88} ;
99
@@ -19,14 +19,18 @@ fn main() {
1919 time_scale : 1f32 ,
2020 substeps : 10 ,
2121 } )
22- . insert_resource ( Time :: < Fixed > :: from_seconds ( 0.4 ) )
22+ . insert_resource ( Time :: < Fixed > :: from_hz ( 5.0 ) )
2323 . add_plugins ( (
2424 DefaultPlugins ,
2525 TransformInterpolationPlugin :: default ( ) ,
2626 RapierPhysicsPlugin :: < NoUserData > :: pixels_per_meter ( 100.0 ) . in_fixed_schedule ( ) ,
2727 RapierDebugRenderPlugin :: default ( ) ,
2828 ) )
2929 . add_systems ( Startup , ( setup_graphics, setup_physics) ) ;
30+ app. add_systems (
31+ PostUpdate ,
32+ debug_with_transform_info. after ( TransformSystem :: TransformPropagate ) ,
33+ ) ;
3034 let mut debugdump_settings = schedule_graph:: Settings :: default ( ) ;
3135 // Filter out some less relevant systems.
3236 debugdump_settings. include_system =
@@ -50,6 +54,8 @@ fn main() {
5054
5155 app. run ( ) ;
5256}
57+ #[ derive( Component , Clone ) ]
58+ pub struct VisualBallDebug ;
5359
5460pub fn setup_graphics ( mut commands : Commands ) {
5561 commands. spawn ( ( Camera2d :: default ( ) , Transform :: from_xyz ( 0.0 , 20.0 , 0.0 ) ) ) ;
@@ -67,24 +73,44 @@ pub fn setup_physics(mut commands: Commands) {
6773 Collider :: cuboid ( ground_size, ground_height) ,
6874 ) ) ;
6975
70- commands . spawn ( (
71- Transform :: from_xyz ( -40 .0, 200.0 , 0.0 ) ,
76+ let interpolated_ball = (
77+ Transform :: from_xyz ( -0 .0, 200.0 , 0.0 ) ,
7278 RigidBody :: Dynamic ,
7379 Collider :: ball ( 20.0 ) ,
7480 Restitution {
75- coefficient : 1.0 ,
81+ coefficient : 0.99 ,
7682 combine_rule : CoefficientCombineRule :: Max ,
7783 } ,
7884 TranslationInterpolation ,
7985 RotationInterpolation ,
86+ VisualBallDebug ,
87+ ) ;
88+ commands. spawn ( interpolated_ball. clone ( ) ) ;
89+ commands. spawn ( interpolated_ball) . insert ( (
90+ ColliderDebug :: NeverRender ,
91+ Transform :: from_xyz ( -80.0 , 200.0 , 0.0 ) ,
8092 ) ) ;
8193 commands. spawn ( (
82- Transform :: from_xyz ( 40 .0, 200.0 , 0.0 ) ,
94+ Transform :: from_xyz ( 80 .0, 200.0 , 0.0 ) ,
8395 RigidBody :: Dynamic ,
8496 Collider :: ball ( 20.0 ) ,
8597 Restitution {
86- coefficient : 1.0 ,
98+ coefficient : 0.99 ,
8799 combine_rule : CoefficientCombineRule :: Max ,
88100 } ,
101+ VisualBallDebug ,
89102 ) ) ;
90103}
104+
105+ pub fn debug_with_transform_info (
106+ mut gizmos : Gizmos ,
107+ entities : Query < ( & Transform , & Collider ) , With < VisualBallDebug > > ,
108+ ) {
109+ for ( transform, collider) in entities. iter ( ) {
110+ gizmos. circle (
111+ transform. translation ,
112+ collider. as_ball ( ) . unwrap ( ) . radius ( ) ,
113+ palettes:: basic:: RED ,
114+ ) ;
115+ }
116+ }
0 commit comments