mirror of
https://github.com/luanti-org/luanti.git
synced 2025-09-15 18:57:08 +00:00
Split liquid_viscosity to liquid_viscosity and move_resistance (#10810)
This commit is contained in:
parent
f5040707fe
commit
21113ad410
15 changed files with 288 additions and 44 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -227,8 +227,9 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
|
|||
pp = floatToInt(position + v3f(0.0f, BS * 0.1f, 0.0f), BS);
|
||||
node = map->getNode(pp, &is_valid_position);
|
||||
if (is_valid_position) {
|
||||
in_liquid = nodemgr->get(node.getContent()).isLiquid();
|
||||
liquid_viscosity = nodemgr->get(node.getContent()).liquid_viscosity;
|
||||
const ContentFeatures &cf = nodemgr->get(node.getContent());
|
||||
in_liquid = cf.liquid_move_physics;
|
||||
move_resistance = cf.move_resistance;
|
||||
} else {
|
||||
in_liquid = false;
|
||||
}
|
||||
|
@ -238,8 +239,9 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
|
|||
pp = floatToInt(position + v3f(0.0f, BS * 0.5f, 0.0f), BS);
|
||||
node = map->getNode(pp, &is_valid_position);
|
||||
if (is_valid_position) {
|
||||
in_liquid = nodemgr->get(node.getContent()).isLiquid();
|
||||
liquid_viscosity = nodemgr->get(node.getContent()).liquid_viscosity;
|
||||
const ContentFeatures &cf = nodemgr->get(node.getContent());
|
||||
in_liquid = cf.liquid_move_physics;
|
||||
move_resistance = cf.move_resistance;
|
||||
} else {
|
||||
in_liquid = false;
|
||||
}
|
||||
|
@ -252,7 +254,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
|
|||
pp = floatToInt(position + v3f(0.0f), BS);
|
||||
node = map->getNode(pp, &is_valid_position);
|
||||
if (is_valid_position) {
|
||||
in_liquid_stable = nodemgr->get(node.getContent()).isLiquid();
|
||||
in_liquid_stable = nodemgr->get(node.getContent()).liquid_move_physics;
|
||||
} else {
|
||||
in_liquid_stable = false;
|
||||
}
|
||||
|
@ -800,8 +802,9 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d,
|
|||
pp = floatToInt(position + v3f(0.0f, BS * 0.1f, 0.0f), BS);
|
||||
node = map->getNode(pp, &is_valid_position);
|
||||
if (is_valid_position) {
|
||||
in_liquid = nodemgr->get(node.getContent()).isLiquid();
|
||||
liquid_viscosity = nodemgr->get(node.getContent()).liquid_viscosity;
|
||||
const ContentFeatures &cf = nodemgr->get(node.getContent());
|
||||
in_liquid = cf.liquid_move_physics;
|
||||
move_resistance = cf.move_resistance;
|
||||
} else {
|
||||
in_liquid = false;
|
||||
}
|
||||
|
@ -810,8 +813,9 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d,
|
|||
pp = floatToInt(position + v3f(0.0f, BS * 0.5f, 0.0f), BS);
|
||||
node = map->getNode(pp, &is_valid_position);
|
||||
if (is_valid_position) {
|
||||
in_liquid = nodemgr->get(node.getContent()).isLiquid();
|
||||
liquid_viscosity = nodemgr->get(node.getContent()).liquid_viscosity;
|
||||
const ContentFeatures &cf = nodemgr->get(node.getContent());
|
||||
in_liquid = cf.liquid_move_physics;
|
||||
move_resistance = cf.move_resistance;
|
||||
} else {
|
||||
in_liquid = false;
|
||||
}
|
||||
|
@ -823,7 +827,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d,
|
|||
pp = floatToInt(position + v3f(0.0f), BS);
|
||||
node = map->getNode(pp, &is_valid_position);
|
||||
if (is_valid_position)
|
||||
in_liquid_stable = nodemgr->get(node.getContent()).isLiquid();
|
||||
in_liquid_stable = nodemgr->get(node.getContent()).liquid_move_physics;
|
||||
else
|
||||
in_liquid_stable = false;
|
||||
|
||||
|
|
|
@ -55,8 +55,8 @@ public:
|
|||
bool in_liquid = false;
|
||||
// This is more stable and defines the maximum speed of the player
|
||||
bool in_liquid_stable = false;
|
||||
// Gets the viscosity of water to calculate friction
|
||||
u8 liquid_viscosity = 0;
|
||||
// Slows down the player when moving through
|
||||
u8 move_resistance = 0;
|
||||
bool is_climbing = false;
|
||||
bool swimming_vertical = false;
|
||||
bool swimming_pitch = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue