]> git.lizzy.rs Git - minetest.git/blobdiff - src/client/clientenvironment.cpp
Split liquid_viscosity to liquid_viscosity and move_resistance (#10810)
[minetest.git] / src / client / clientenvironment.cpp
index 7e3867537001ed30529aa8c7f60c55c703c484bc..448af36c6596e982a144d16958db7eed0ed41a65 100644 (file)
@@ -194,32 +194,41 @@ void ClientEnvironment::step(float dtime)
                lplayer->applyControl(dtime_part, this);
 
                // Apply physics
-               if (!free_move && !is_climbing) {
+               if (!free_move) {
                        // Gravity
                        v3f speed = lplayer->getSpeed();
-                       if (!lplayer->in_liquid)
+                       if (!is_climbing && !lplayer->in_liquid)
                                speed.Y -= lplayer->movement_gravity *
                                        lplayer->physics_override_gravity * dtime_part * 2.0f;
 
                        // Liquid floating / sinking
-                       if (lplayer->in_liquid && !lplayer->swimming_vertical &&
+                       if (!is_climbing && lplayer->in_liquid &&
+                                       !lplayer->swimming_vertical &&
                                        !lplayer->swimming_pitch)
                                speed.Y -= lplayer->movement_liquid_sink * dtime_part * 2.0f;
 
-                       // Liquid resistance
-                       if (lplayer->in_liquid_stable || lplayer->in_liquid) {
-                               // How much the node's viscosity blocks movement, ranges
-                               // between 0 and 1. Should match the scale at which viscosity
+                       // Movement resistance
+                       if (lplayer->move_resistance > 0) {
+                               // How much the node's move_resistance blocks movement, ranges
+                               // between 0 and 1. Should match the scale at which liquid_viscosity
                                // increase affects other liquid attributes.
-                               static const f32 viscosity_factor = 0.3f;
-
-                               v3f d_wanted = -speed / lplayer->movement_liquid_fluidity;
+                               static const f32 resistance_factor = 0.3f;
+
+                               v3f d_wanted;
+                               bool in_liquid_stable = lplayer->in_liquid_stable || lplayer->in_liquid;
+                               if (in_liquid_stable) {
+                                       d_wanted = -speed / lplayer->movement_liquid_fluidity;
+                               } else {
+                                       d_wanted = -speed / BS;
+                               }
                                f32 dl = d_wanted.getLength();
-                               if (dl > lplayer->movement_liquid_fluidity_smooth)
-                                       dl = lplayer->movement_liquid_fluidity_smooth;
+                               if (in_liquid_stable) {
+                                       if (dl > lplayer->movement_liquid_fluidity_smooth)
+                                               dl = lplayer->movement_liquid_fluidity_smooth;
+                               }
 
-                               dl *= (lplayer->liquid_viscosity * viscosity_factor) +
-                                       (1 - viscosity_factor);
+                               dl *= (lplayer->move_resistance * resistance_factor) +
+                                       (1 - resistance_factor);
                                v3f d = d_wanted.normalize() * (dl * dtime_part * 100.0f);
                                speed += d;
                        }