MCPcopy Create free account
hub / github.com/Panzerschrek/Chasm-Reverse / Move

Method Move

PanzerChasm/server/player.cpp:744–848  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

742}
743
744bool Player::Move( const Time time_delta )
745{
746 const float time_delta_s= time_delta.ToSeconds();
747
748 // TODO - calibrate this
749 const float c_acceleration= 40.0f;
750 const float c_deceleration= 20.0f;
751 const float c_jump_speed_delta= 2.9f;
752
753 const float speed_delta= time_delta_s * mevement_acceleration_ * c_acceleration;
754 const float deceleration_speed_delta= time_delta_s * c_deceleration;
755
756 // Accelerate
757 m_Vec2 acceleration( 0.0f, 0.0f );
758 if( state_ == State::Alive )
759 {
760 acceleration.x= std::cos( movement_direction_ ) * speed_delta;
761 acceleration.y= std::sin( movement_direction_ ) * speed_delta;
762 }
763
764 // Decelerate
765 const float new_speed_length= speed_.xy().Length();
766 if( new_speed_length >= deceleration_speed_delta )
767 {
768 const float k= ( new_speed_length - deceleration_speed_delta ) / new_speed_length;
769 speed_.x*= k;
770 speed_.y*= k;
771 }
772 else
773 speed_.x= speed_.y= 0.0f;
774
775 const m_Vec2 current_speed_xy= speed_.xy();
776 const float acceleration_projection_to_current_speed= acceleration * current_speed_xy;
777 if( acceleration_projection_to_current_speed > 0.0f )
778 {
779 const float max_square_speed= GameConstants::player_max_speed * GameConstants::player_max_speed;
780
781 const float current_speed_square_length= current_speed_xy.SquareLength();
782 const m_Vec2 acceleration_projection= current_speed_xy * ( acceleration_projection_to_current_speed / current_speed_square_length );
783 const m_Vec2 acceleration_orthogonal= acceleration - acceleration_projection;
784
785 // If speed greater, then maximal speed by player, just add only orthogonal to current speed aceleration part.
786 if( current_speed_square_length >= max_square_speed )
787 {
788 speed_.x+= acceleration_orthogonal.x;
789 speed_.y+= acceleration_orthogonal.y;
790 }
791 else
792 {
793 // Extend current speed as much, as can and add orthogonal ecceleration component.
794 m_Vec2 speed_plus_acceleration_projection= current_speed_xy + acceleration_projection;
795 const float speed_plus_acceleration_projection_squar_length= speed_plus_acceleration_projection.SquareLength();
796 if( speed_plus_acceleration_projection_squar_length > max_square_speed )
797 speed_plus_acceleration_projection*=
798 GameConstants::player_max_speed / std::sqrt( speed_plus_acceleration_projection_squar_length );
799
800 speed_.x= speed_plus_acceleration_projection.x + acceleration_orthogonal.x;
801 speed_.y= speed_plus_acceleration_projection.y + acceleration_orthogonal.y;

Callers

nothing calls this directly

Calls 1

ToSecondsMethod · 0.80

Tested by

no test coverage detected