mirror of
https://github.com/minetest/minetest.git
synced 2025-06-30 23:20:22 +02:00
New physics overrides (#11465)
This commit is contained in:
@ -208,7 +208,7 @@ void ClientEnvironment::step(float dtime)
|
||||
!lplayer->swimming_vertical &&
|
||||
!lplayer->swimming_pitch)
|
||||
// HACK the factor 2 for gravity is arbitrary and should be removed eventually
|
||||
lplayer->gravity = 2 * lplayer->movement_liquid_sink;
|
||||
lplayer->gravity = 2 * lplayer->movement_liquid_sink * lplayer->physics_override.liquid_sink;
|
||||
|
||||
// Movement resistance
|
||||
if (lplayer->move_resistance > 0) {
|
||||
@ -218,20 +218,22 @@ void ClientEnvironment::step(float dtime)
|
||||
// between 0 and 1. Should match the scale at which liquid_viscosity
|
||||
// increase affects other liquid attributes.
|
||||
static const f32 resistance_factor = 0.3f;
|
||||
float fluidity = lplayer->movement_liquid_fluidity;
|
||||
fluidity *= MYMAX(1.0f, lplayer->physics_override.liquid_fluidity);
|
||||
fluidity = MYMAX(0.001f, fluidity); // prevent division by 0
|
||||
float fluidity_smooth = lplayer->movement_liquid_fluidity_smooth;
|
||||
fluidity_smooth *= lplayer->physics_override.liquid_fluidity_smooth;
|
||||
fluidity_smooth = MYMAX(0.0f, fluidity_smooth);
|
||||
|
||||
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 {
|
||||
if (in_liquid_stable)
|
||||
d_wanted = -speed / fluidity;
|
||||
else
|
||||
d_wanted = -speed / BS;
|
||||
}
|
||||
f32 dl = d_wanted.getLength();
|
||||
if (in_liquid_stable) {
|
||||
if (dl > lplayer->movement_liquid_fluidity_smooth)
|
||||
dl = lplayer->movement_liquid_fluidity_smooth;
|
||||
}
|
||||
|
||||
if (in_liquid_stable)
|
||||
dl = MYMIN(dl, fluidity_smooth);
|
||||
dl *= (lplayer->move_resistance * resistance_factor) +
|
||||
(1 - resistance_factor);
|
||||
v3f d = d_wanted.normalize() * (dl * dtime_part * 100.0f);
|
||||
|
@ -1775,6 +1775,23 @@ void GenericCAO::processMessage(const std::string &data)
|
||||
bool sneak_glitch = !readU8(is);
|
||||
bool new_move = !readU8(is);
|
||||
|
||||
float override_speed_climb = readF32(is);
|
||||
float override_speed_crouch = readF32(is);
|
||||
float override_liquid_fluidity = readF32(is);
|
||||
float override_liquid_fluidity_smooth = readF32(is);
|
||||
float override_liquid_sink = readF32(is);
|
||||
float override_acceleration_default = readF32(is);
|
||||
float override_acceleration_air = readF32(is);
|
||||
// fallback for new overrides (since 5.8.0)
|
||||
if (is.eof()) {
|
||||
override_speed_climb = 1.0f;
|
||||
override_speed_crouch = 1.0f;
|
||||
override_liquid_fluidity = 1.0f;
|
||||
override_liquid_fluidity_smooth = 1.0f;
|
||||
override_liquid_sink = 1.0f;
|
||||
override_acceleration_default = 1.0f;
|
||||
override_acceleration_air = 1.0f;
|
||||
}
|
||||
|
||||
if (m_is_local_player) {
|
||||
auto &phys = m_env->getLocalPlayer()->physics_override;
|
||||
@ -1784,6 +1801,13 @@ void GenericCAO::processMessage(const std::string &data)
|
||||
phys.sneak = sneak;
|
||||
phys.sneak_glitch = sneak_glitch;
|
||||
phys.new_move = new_move;
|
||||
phys.speed_climb = override_speed_climb;
|
||||
phys.speed_crouch = override_speed_crouch;
|
||||
phys.liquid_fluidity = override_liquid_fluidity;
|
||||
phys.liquid_fluidity_smooth = override_liquid_fluidity_smooth;
|
||||
phys.liquid_sink = override_liquid_sink;
|
||||
phys.acceleration_default = override_acceleration_default;
|
||||
phys.acceleration_air = override_acceleration_air;
|
||||
}
|
||||
} else if (cmd == AO_CMD_SET_ANIMATION) {
|
||||
// TODO: change frames send as v2s32 value
|
||||
|
@ -557,7 +557,7 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
|
||||
speedV.Y = -movement_speed_walk;
|
||||
swimming_vertical = true;
|
||||
} else if (is_climbing && !m_disable_descend) {
|
||||
speedV.Y = -movement_speed_climb;
|
||||
speedV.Y = -movement_speed_climb * physics_override.speed_climb;
|
||||
} else {
|
||||
// If not free movement but fast is allowed, aux1 is
|
||||
// "Turbo button"
|
||||
@ -595,7 +595,7 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
|
||||
if (fast_climb)
|
||||
speedV.Y = -movement_speed_fast;
|
||||
else
|
||||
speedV.Y = -movement_speed_climb;
|
||||
speedV.Y = -movement_speed_climb * physics_override.speed_climb;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -647,7 +647,7 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
|
||||
if (fast_climb)
|
||||
speedV.Y = movement_speed_fast;
|
||||
else
|
||||
speedV.Y = movement_speed_climb;
|
||||
speedV.Y = movement_speed_climb * physics_override.speed_climb;
|
||||
}
|
||||
}
|
||||
|
||||
@ -656,7 +656,7 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
|
||||
((in_liquid || in_liquid_stable) && fast_climb))
|
||||
speedH = speedH.normalize() * movement_speed_fast;
|
||||
else if (control.sneak && !free_move && !in_liquid && !in_liquid_stable)
|
||||
speedH = speedH.normalize() * movement_speed_crouch;
|
||||
speedH = speedH.normalize() * movement_speed_crouch * physics_override.speed_crouch;
|
||||
else
|
||||
speedH = speedH.normalize() * movement_speed_walk;
|
||||
|
||||
@ -671,13 +671,13 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
|
||||
if (superspeed || (fast_move && control.aux1))
|
||||
incH = movement_acceleration_fast * BS * dtime;
|
||||
else
|
||||
incH = movement_acceleration_air * BS * dtime;
|
||||
incH = movement_acceleration_air * physics_override.acceleration_air * BS * dtime;
|
||||
incV = 0.0f; // No vertical acceleration in air
|
||||
} else if (superspeed || (is_climbing && fast_climb) ||
|
||||
((in_liquid || in_liquid_stable) && fast_climb)) {
|
||||
incH = incV = movement_acceleration_fast * BS * dtime;
|
||||
} else {
|
||||
incH = incV = movement_acceleration_default * BS * dtime;
|
||||
incH = incV = movement_acceleration_default * physics_override.acceleration_default * BS * dtime;
|
||||
}
|
||||
|
||||
float slip_factor = 1.0f;
|
||||
|
Reference in New Issue
Block a user