1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-12 16:58:39 +00:00

Split liquid_viscosity to liquid_viscosity and move_resistance (#10810)

This commit is contained in:
Wuzzy 2021-10-01 14:21:24 +00:00 committed by GitHub
parent f5040707fe
commit 21113ad410
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 288 additions and 44 deletions

View 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;
static const f32 resistance_factor = 0.3f;
v3f d_wanted = -speed / lplayer->movement_liquid_fluidity;
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;
}