@@ -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
694694v3s16 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
0 commit comments