11use bevy_ecs:: prelude:: * ;
22use ferrumc_core:: transform:: grounded:: OnGround ;
33use ferrumc_core:: transform:: position:: Position ;
4- use ferrumc_entities:: collision:: { check_collision, BoundingBox } ;
4+ use ferrumc_entities:: collision:: { check_collision, is_in_water , BoundingBox } ;
55use ferrumc_entities:: components:: * ;
66use ferrumc_state:: GlobalStateResource ;
77
88const GRAVITY : f64 = -0.08 ; // Blocks per tick^2
99const TERMINAL_VELOCITY : f64 = -3.92 ; // Max fall speed
10+ const WATER_BUOYANCY : f64 = 0.10 ; // Upward force in water (stronger than gravity to make entities float)
11+ const WATER_DRAG : f64 = 0.8 ; // Water friction multiplier
1012
1113/// System that apply basic physics to entity
1214pub fn entity_physics_system (
@@ -17,11 +19,19 @@ pub fn entity_physics_system(
1719 let bbox = BoundingBox :: PIG ;
1820
1921 for ( mut pos, mut vel, on_ground) in query. iter_mut ( ) {
20- // Apply gravity if not on ground
21- if !on_ground. 0 {
22+ // Check if entity is in water
23+ let in_water = is_in_water ( & state. 0 , pos. x , pos. y , pos. z , & bbox) ;
24+
25+ // Apply gravity and buoyancy
26+ if in_water {
27+ // In water: buoyancy force is stronger than gravity, so entities float up
28+ vel. y += GRAVITY + WATER_BUOYANCY ;
29+ // Net force: -0.08 + 0.10 = +0.02 (upward), causing floating
30+ } else if !on_ground. 0 {
31+ // In air: normal gravity
2232 vel. y = ( vel. y + GRAVITY ) . max ( TERMINAL_VELOCITY ) ;
2333 } else {
24- // Reset velocity Y if on ground
34+ // On ground: reset downward velocity
2535 if vel. y < 0.0 {
2636 vel. y = 0.0 ;
2737 }
@@ -63,11 +73,18 @@ pub fn entity_physics_system(
6373 }
6474 }
6575
66- if on_ground. 0 {
67- // Less friction on ground for better movement (was 0.6)
76+ // Apply friction based on environment
77+ if in_water {
78+ // Water drag - slows movement significantly
79+ vel. x *= WATER_DRAG ;
80+ vel. z *= WATER_DRAG ;
81+ vel. y *= 0.95 ; // Vertical water drag
82+ } else if on_ground. 0 {
83+ // Ground friction
6884 vel. x *= 0.85 ;
6985 vel. z *= 0.85 ;
7086 } else {
87+ // Air resistance
7188 vel. x *= 0.98 ;
7289 vel. z *= 0.98 ;
7390 }
0 commit comments