1
1
use crate :: prelude:: * ;
2
2
3
3
static COLLIDER_GRID_SIZE : u32 = 3 ;
4
- static COLLIDER_RESTING_POSITION : Vec3 = Vec3 :: new ( 0.0 , 0.0 , 0.0 ) ;
4
+ static COLLIDER_RESTING_POSITION : Vec3 = Vec3 :: ZERO ;
5
5
6
6
pub fn setup_coliders_system ( mut commands : Commands ) {
7
7
let collider_range = 0 ..COLLIDER_GRID_SIZE ;
@@ -12,10 +12,16 @@ pub fn setup_coliders_system(mut commands: Commands) {
12
12
commands
13
13
. spawn ( Collider :: cuboid ( 0.5 , 0.5 , 0.5 ) )
14
14
. insert ( TransformBundle :: from ( Transform :: from_xyz (
15
- x as f32 , y as f32 , z as f32 ,
15
+ x as f32 , y as f32 , z as f32 ,
16
16
) ) )
17
- . insert ( collider_components:: MyCollider { relative_position : Vec3 { x : x as f32 , y : y as f32 , z : z as f32 } } ) ;
18
- }
17
+ . insert ( collider_components:: MyCollider {
18
+ relative_position : Vec3 {
19
+ x : x as f32 ,
20
+ y : y as f32 ,
21
+ z : z as f32 ,
22
+ } ,
23
+ } ) ;
24
+ }
19
25
}
20
26
}
21
27
}
@@ -26,8 +32,12 @@ pub fn handle_collider_update_events_system(
26
32
mut chunk_manager : ResMut < terrain_resources:: ChunkManager > ,
27
33
) {
28
34
for event in collider_grid_events. read ( ) {
29
- let event_position =
30
- Vec3 :: new ( event. grid_center_position [ 0 ] , event. grid_center_position [ 1 ] , event. grid_center_position [ 2 ] ) . floor ( ) ;
35
+ let event_position = Vec3 :: new (
36
+ event. grid_center_position [ 0 ] ,
37
+ event. grid_center_position [ 1 ] ,
38
+ event. grid_center_position [ 2 ] ,
39
+ )
40
+ . floor ( ) ;
31
41
for ( mut transform, collider) in query. iter_mut ( ) {
32
42
let relative_position = collider. relative_position ;
33
43
let collider_position = ( event_position + relative_position) . floor ( ) ;
@@ -82,15 +92,21 @@ mod tests {
82
92
app. insert_resource ( terrain_resources:: ChunkManager :: new ( ) ) ;
83
93
84
94
app. world . spawn ( (
85
- Transform {
86
- translation : Vec3 {
87
- x : 0.0 ,
88
- y : 0.0 ,
89
- z : 0.0 ,
90
- } ,
91
- ..Default :: default ( )
95
+ Transform {
96
+ translation : Vec3 {
97
+ x : 0.0 ,
98
+ y : 0.0 ,
99
+ z : 0.0 ,
92
100
} ,
93
- collider_components:: MyCollider { relative_position : Vec3 { x : 1.0 , y : 2.0 , z : 3.0 } } ,
101
+ ..Default :: default ( )
102
+ } ,
103
+ collider_components:: MyCollider {
104
+ relative_position : Vec3 {
105
+ x : 1.0 ,
106
+ y : 2.0 ,
107
+ z : 3.0 ,
108
+ } ,
109
+ } ,
94
110
) ) ;
95
111
96
112
let block = BlockId :: Dirt ;
0 commit comments