Skip to content

Commit 327bad2

Browse files
gaelysamSmallJoker
authored andcommittedDec 1, 2018
Added pitch fly mode (#7817)
In pitch fly mode, you fly to the exact direction you are pointing at, using the forward key. Other move directions are also pitched accordingly. It allows smoother and more complex movements. Can be enabled/disabled by L key by default (set keymap_pitchfly in minetest.conf)
1 parent dcf58a3 commit 327bad2

11 files changed

+93
-46
lines changed
 

Diff for: ‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Some can be changed in the key config dialog in the settings tab.
5252
| + | Increase view range |
5353
| - | Decrease view range |
5454
| K | Enable/disable fly mode (needs fly privilege) |
55+
| L | Enable/disable pitch fly mode |
5556
| J | Enable/disable fast mode (needs fast privilege) |
5657
| H | Enable/disable noclip mode (needs noclip privilege) |
5758
| E | Move fast in fast mode |

Diff for: ‎builtin/settingtypes.txt

+7
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ enable_build_where_you_stand (Build inside player) bool false
7272
# This requires the "fly" privilege on the server.
7373
free_move (Flying) bool false
7474

75+
# If enabled together with fly mode, makes move directions relative to the player's pitch.
76+
pitch_fly (Pitch fly mode) bool false
77+
7578
# Fast movement (via the "special" key).
7679
# This requires the "fast" privilege on the server.
7780
fast_move (Fast movement) bool false
@@ -208,6 +211,10 @@ keymap_rangeselect (Range select key) key KEY_KEY_R
208211
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
209212
keymap_freemove (Fly key) key KEY_KEY_K
210213

214+
# Key for toggling pitch fly mode.
215+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
216+
keymap_pitchfly (Pitch fly key) key KEY_KEY_L
217+
211218
# Key for toggling fast mode.
212219
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
213220
keymap_fastmove (Fast key) key KEY_KEY_J

Diff for: ‎minetest.conf.example

+9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
# type: bool
2727
# free_move = false
2828

29+
# If enabled together with fly mode, makes move directions relative to the player's pitch.
30+
# type: bool
31+
# pitch_fly = false
32+
2933
# Fast movement (via the "special" key).
3034
# This requires the "fast" privilege on the server.
3135
# type: bool
@@ -194,6 +198,11 @@
194198
# type: key
195199
# keymap_freemove = KEY_KEY_K
196200

201+
# Key for toggling pitch fly mode.
202+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
203+
# type: key
204+
# keymap_pitchfly = KEY_KEY_L
205+
197206
# Key for toggling fast mode.
198207
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
199208
# type: key

Diff for: ‎src/client/game.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@ class Game {
701701
void openConsole(float scale, const wchar_t *line=NULL);
702702
void toggleFreeMove();
703703
void toggleFreeMoveAlt();
704+
void togglePitchFly();
704705
void toggleFast();
705706
void toggleNoClip();
706707
void toggleCinematic();
@@ -1896,6 +1897,8 @@ void Game::processKeyInput()
18961897
toggleFreeMove();
18971898
} else if (wasKeyDown(KeyType::JUMP)) {
18981899
toggleFreeMoveAlt();
1900+
} else if (wasKeyDown(KeyType::PITCHFLY)) {
1901+
togglePitchFly();
18991902
} else if (wasKeyDown(KeyType::FASTMOVE)) {
19001903
toggleFast();
19011904
} else if (wasKeyDown(KeyType::NOCLIP)) {
@@ -2107,6 +2110,19 @@ void Game::toggleFreeMoveAlt()
21072110
}
21082111

21092112

2113+
void Game::togglePitchFly()
2114+
{
2115+
bool pitch_fly = !g_settings->getBool("pitch_fly");
2116+
g_settings->set("pitch_fly", bool_to_cstr(pitch_fly));
2117+
2118+
if (pitch_fly) {
2119+
m_game_ui->showTranslatedStatusText("Pitch fly mode enabled");
2120+
} else {
2121+
m_game_ui->showTranslatedStatusText("Pitch fly mode disabled");
2122+
}
2123+
}
2124+
2125+
21102126
void Game::toggleFast()
21112127
{
21122128
bool fast_move = !g_settings->getBool("fast_move");

Diff for: ‎src/client/inputhandler.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ void KeyCache::populate()
4747
key[KeyType::CONSOLE] = getKeySetting("keymap_console");
4848
key[KeyType::MINIMAP] = getKeySetting("keymap_minimap");
4949
key[KeyType::FREEMOVE] = getKeySetting("keymap_freemove");
50+
key[KeyType::PITCHFLY] = getKeySetting("keymap_pitchfly");
5051
key[KeyType::FASTMOVE] = getKeySetting("keymap_fastmove");
5152
key[KeyType::NOCLIP] = getKeySetting("keymap_noclip");
5253
key[KeyType::HOTBAR_PREV] = getKeySetting("keymap_hotbar_previous");

Diff for: ‎src/client/keys.h

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class KeyType
4747
CONSOLE,
4848
MINIMAP,
4949
FREEMOVE,
50+
PITCHFLY,
5051
FASTMOVE,
5152
NOCLIP,
5253
HOTBAR_PREV,

Diff for: ‎src/client/localplayer.cpp

+50-42
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,9 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
481481

482482
PlayerSettings &player_settings = getPlayerSettings();
483483

484-
v3f move_direction = v3f(0,0,1);
485-
move_direction.rotateXZBy(getYaw());
486-
484+
// All vectors are relative to the player's yaw,
485+
// (and pitch if pitch fly mode enabled),
486+
// and will be rotated at the end
487487
v3f speedH = v3f(0,0,0); // Horizontal (X, Z)
488488
v3f speedV = v3f(0,0,0); // Vertical (Y)
489489

@@ -492,6 +492,7 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
492492

493493
bool free_move = fly_allowed && player_settings.free_move;
494494
bool fast_move = fast_allowed && player_settings.fast_move;
495+
bool pitch_fly = free_move && player_settings.pitch_fly;
495496
// When aux1_descends is enabled the fast key is used to go down, so fast isn't possible
496497
bool fast_climb = fast_move && control.aux1 && !player_settings.aux1_descends;
497498
bool continuous_forward = player_settings.continuous_forward;
@@ -582,31 +583,31 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
582583
}
583584

584585
if (continuous_forward)
585-
speedH += move_direction;
586+
speedH += v3f(0,0,1);
586587

587588
if (control.up) {
588589
if (continuous_forward) {
589590
if (fast_move)
590591
superspeed = true;
591592
} else {
592-
speedH += move_direction;
593+
speedH += v3f(0,0,1);
593594
}
594595
}
595596
if (control.down) {
596-
speedH -= move_direction;
597+
speedH -= v3f(0,0,1);
597598
}
598599
if (!control.up && !control.down) {
599-
speedH -= move_direction *
600+
speedH -= v3f(0,0,1) *
600601
(control.forw_move_joystick_axis / 32767.f);
601602
}
602603
if (control.left) {
603-
speedH += move_direction.crossProduct(v3f(0,1,0));
604+
speedH += v3f(-1,0,0);
604605
}
605606
if (control.right) {
606-
speedH += move_direction.crossProduct(v3f(0,-1,0));
607+
speedH += v3f(1,0,0);
607608
}
608609
if (!control.left && !control.right) {
609-
speedH -= move_direction.crossProduct(v3f(0,1,0)) *
610+
speedH += v3f(1,0,0) *
610611
(control.sidew_move_joystick_axis / 32767.f);
611612
}
612613
if(control.jump)
@@ -685,10 +686,9 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
685686
slip_factor = getSlipFactor(env, speedH);
686687

687688
// Accelerate to target speed with maximum increment
688-
accelerateHorizontal(speedH * physics_override_speed,
689-
incH * physics_override_speed * slip_factor);
690-
accelerateVertical(speedV * physics_override_speed,
691-
incV * physics_override_speed);
689+
accelerate((speedH + speedV) * physics_override_speed,
690+
incH * physics_override_speed * slip_factor, incV * physics_override_speed,
691+
pitch_fly);
692692
}
693693

694694
v3s16 LocalPlayer::getStandingNodePos()
@@ -725,38 +725,46 @@ v3f LocalPlayer::getEyeOffset() const
725725
return v3f(0, BS * eye_height, 0);
726726
}
727727

728-
// Horizontal acceleration (X and Z), Y direction is ignored
729-
void LocalPlayer::accelerateHorizontal(const v3f &target_speed,
730-
const f32 max_increase)
728+
// 3D acceleration
729+
void LocalPlayer::accelerate(const v3f &target_speed, const f32 max_increase_H,
730+
const f32 max_increase_V, const bool use_pitch)
731731
{
732-
if (max_increase == 0)
733-
return;
734-
735-
v3f d_wanted = target_speed - m_speed;
736-
d_wanted.Y = 0.0f;
737-
f32 dl = d_wanted.getLength();
738-
if (dl > max_increase)
739-
dl = max_increase;
740-
741-
v3f d = d_wanted.normalize() * dl;
742-
743-
m_speed.X += d.X;
744-
m_speed.Z += d.Z;
745-
}
732+
const f32 yaw = getYaw();
733+
const f32 pitch = getPitch();
734+
v3f flat_speed = m_speed;
735+
// Rotate speed vector by -yaw and -pitch to make it relative to the player's yaw and pitch
736+
flat_speed.rotateXZBy(-yaw);
737+
if (use_pitch)
738+
flat_speed.rotateYZBy(-pitch);
739+
740+
v3f d_wanted = target_speed - flat_speed;
741+
v3f d = v3f(0,0,0);
742+
743+
// Then compare the horizontal and vertical components with the wanted speed
744+
if (max_increase_H > 0) {
745+
v3f d_wanted_H = d_wanted * v3f(1,0,1);
746+
if (d_wanted_H.getLength() > max_increase_H)
747+
d += d_wanted_H.normalize() * max_increase_H;
748+
else
749+
d += d_wanted_H;
750+
}
746751

747-
// Vertical acceleration (Y), X and Z directions are ignored
748-
void LocalPlayer::accelerateVertical(const v3f &target_speed, const f32 max_increase)
749-
{
750-
if (max_increase == 0)
751-
return;
752+
if (max_increase_V > 0) {
753+
f32 d_wanted_V = d_wanted.Y;
754+
if (d_wanted_V > max_increase_V)
755+
d.Y += max_increase_V;
756+
else if (d_wanted_V < -max_increase_V)
757+
d.Y -= max_increase_V;
758+
else
759+
d.Y += d_wanted_V;
760+
}
752761

753-
f32 d_wanted = target_speed.Y - m_speed.Y;
754-
if (d_wanted > max_increase)
755-
d_wanted = max_increase;
756-
else if (d_wanted < -max_increase)
757-
d_wanted = -max_increase;
762+
// Finally rotate it again
763+
if (use_pitch)
764+
d.rotateYZBy(pitch);
765+
d.rotateXZBy(yaw);
758766

759-
m_speed.Y += d_wanted;
767+
m_speed += d;
760768
}
761769

762770
// Temporary option for old move code

Diff for: ‎src/client/localplayer.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ class LocalPlayer : public Player
149149
bool getAutojump() const { return m_autojump; }
150150

151151
private:
152-
void accelerateHorizontal(const v3f &target_speed, const f32 max_increase);
153-
void accelerateVertical(const v3f &target_speed, const f32 max_increase);
152+
void accelerate(const v3f &target_speed, const f32 max_increase_H,
153+
const f32 max_increase_V, const bool use_pitch);
154154
bool updateSneakNode(Map *map, const v3f &position, const v3f &sneak_max);
155155
float getSlipFactor(Environment *env, const v3f &speedH);
156156
void handleAutojump(f32 dtime, Environment *env,

Diff for: ‎src/defaultsettings.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void set_default_settings(Settings *settings)
4343
settings->setDefault("meshgen_block_cache_size", "20");
4444
settings->setDefault("enable_vbo", "true");
4545
settings->setDefault("free_move", "false");
46+
settings->setDefault("pitch_fly", "false");
4647
settings->setDefault("fast_move", "false");
4748
settings->setDefault("noclip", "false");
4849
settings->setDefault("screenshot_path", ".");
@@ -80,6 +81,7 @@ void set_default_settings(Settings *settings)
8081
settings->setDefault("keymap_console", "KEY_F10");
8182
settings->setDefault("keymap_rangeselect", "KEY_KEY_R");
8283
settings->setDefault("keymap_freemove", "KEY_KEY_K");
84+
settings->setDefault("keymap_pitchfly", "KEY_KEY_L");
8385
settings->setDefault("keymap_fastmove", "KEY_KEY_J");
8486
settings->setDefault("keymap_noclip", "KEY_KEY_H");
8587
settings->setDefault("keymap_hotbar_next", "KEY_KEY_N");

Diff for: ‎src/player.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ void Player::clearHud()
139139
void PlayerSettings::readGlobalSettings()
140140
{
141141
free_move = g_settings->getBool("free_move");
142+
pitch_fly = g_settings->getBool("pitch_fly");
142143
fast_move = g_settings->getBool("fast_move");
143144
continuous_forward = g_settings->getBool("continuous_forward");
144145
always_fly_fast = g_settings->getBool("always_fly_fast");

Diff for: ‎src/player.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,16 @@ struct PlayerControl
8787
struct PlayerSettings
8888
{
8989
bool free_move = false;
90+
bool pitch_fly = false;
9091
bool fast_move = false;
9192
bool continuous_forward = false;
9293
bool always_fly_fast = false;
9394
bool aux1_descends = false;
9495
bool noclip = false;
9596
bool autojump = false;
9697

97-
const std::string setting_names[7] = {
98-
"free_move", "fast_move", "continuous_forward", "always_fly_fast",
98+
const std::string setting_names[8] = {
99+
"free_move", "pitch_fly", "fast_move", "continuous_forward", "always_fly_fast",
99100
"aux1_descends", "noclip", "autojump"
100101
};
101102
void readGlobalSettings();

0 commit comments

Comments
 (0)
Please sign in to comment.