From 73d6465095193fa58a641386c033f96a5ffc7e91 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Sun, 7 Jun 2020 14:12:51 -0400 Subject: [PATCH] CPlayer: Fix logic in ChooseTransitionToAnimation --- Runtime/World/CPlayer.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Runtime/World/CPlayer.cpp b/Runtime/World/CPlayer.cpp index ae83548d3..f3d06898e 100644 --- a/Runtime/World/CPlayer.cpp +++ b/Runtime/World/CPlayer.cpp @@ -177,6 +177,8 @@ constexpr std::array skRightStepSounds{ SFXsam_b_wlkorg_01, }; +constexpr float RCP_2PI = 0.15915494; + constexpr std::array, 4> skVisorToItemMapping{{ {CPlayerState::EItemType::CombatVisor, ControlMapper::ECommands::NoVisor}, {CPlayerState::EItemType::XRayVisor, ControlMapper::ECommands::XrayVisor}, @@ -301,8 +303,14 @@ s32 CPlayer::ChooseTransitionToAnimation(float dt, CStateManager& mgr) const { return 2; // B_readytoball_samus } - const zeus::CRelAngle velAng = std::atan2(localVelFlat.x(), localVelFlat.y()); - const float velDeg = velAng.asDegrees(); + float velAng = std::atan2(-localVelFlat.x(), localVelFlat.y()); + constexpr float twoPi = zeus::degToRad(360.f); + if (velAng > twoPi) { + velAng = velAng - static_cast(velAng * RCP_2PI) * twoPi; + } else if (velAng < 0.f) { + velAng = twoPi + (velAng - static_cast(velAng * RCP_2PI) * twoPi); + } + const float velDeg = zeus::radToDeg(velAng); if (velDeg >= 45.f && velDeg <= 315.f) { return 1; // B_readytostationarybackwards_samus } @@ -312,7 +320,6 @@ s32 CPlayer::ChooseTransitionToAnimation(float dt, CStateManager& mgr) const { } return 4; // B_runtoballfoward_samus - } void CPlayer::TransitionToMorphBallState(float dt, CStateManager& mgr) {