1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Player::accelerateHorizontal/Vertical should be member of LocalPlayer

This commit is contained in:
Loic Blot 2016-02-14 17:45:06 +01:00
parent cfc8e44759
commit 3a74b84007
4 changed files with 37 additions and 39 deletions

View file

@ -622,3 +622,36 @@ v3s16 LocalPlayer::getStandingNodePos()
return floatToInt(getPosition() - v3f(0, BS, 0), BS);
}
// Horizontal acceleration (X and Z), Y direction is ignored
void LocalPlayer::accelerateHorizontal(const v3f &target_speed, const f32 max_increase)
{
if (max_increase == 0)
return;
v3f d_wanted = target_speed - m_speed;
d_wanted.Y = 0;
f32 dl = d_wanted.getLength();
if (dl > max_increase)
dl = max_increase;
v3f d = d_wanted.normalize() * dl;
m_speed.X += d.X;
m_speed.Z += d.Z;
}
// Vertical acceleration (Y), X and Z directions are ignored
void LocalPlayer::accelerateVertical(const v3f &target_speed, const f32 max_increase)
{
if (max_increase == 0)
return;
f32 d_wanted = target_speed.Y - m_speed.Y;
if (d_wanted > max_increase)
d_wanted = max_increase;
else if (d_wanted < -max_increase)
d_wanted = -max_increase;
m_speed.Y += d_wanted;
}