| 1902 | } |
| 1903 | |
| 1904 | void UAlsAnimationInstance::RefreshTurnInPlace() |
| 1905 | { |
| 1906 | #if WITH_EDITOR |
| 1907 | if (!IsValid(GetWorld()) || !GetWorld()->IsGameWorld()) |
| 1908 | { |
| 1909 | return; |
| 1910 | } |
| 1911 | #endif |
| 1912 | |
| 1913 | DECLARE_SCOPE_CYCLE_COUNTER(TEXT("UAlsAnimationInstance::RefreshTurnInPlace"), |
| 1914 | STAT_UAlsAnimationInstance_RefreshTurnInPlace, STATGROUP_Als) |
| 1915 | TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__) |
| 1916 | |
| 1917 | if (TurnInPlaceState.bUpdatedThisFrame || !IsValid(Settings)) |
| 1918 | { |
| 1919 | return; |
| 1920 | } |
| 1921 | |
| 1922 | TurnInPlaceState.bUpdatedThisFrame = true; |
| 1923 | |
| 1924 | if (!TransitionsState.bTransitionsAllowed || !IsTurnInPlaceAllowed()) |
| 1925 | { |
| 1926 | TurnInPlaceState.ActivationDelay = 0.0f; |
| 1927 | return; |
| 1928 | } |
| 1929 | |
| 1930 | // Check if the view yaw speed is below the threshold and if the view yaw angle is outside the |
| 1931 | // threshold. If so, begin counting the activation delay time. If not, reset the activation delay |
| 1932 | // time. This ensures the conditions remain true for a sustained time before turning in place. |
| 1933 | |
| 1934 | if (ViewState.YawSpeed >= Settings->TurnInPlace.ViewYawSpeedThreshold || |
| 1935 | FMath::Abs(ViewState.YawAngle) <= Settings->TurnInPlace.ViewYawAngleThreshold) |
| 1936 | { |
| 1937 | TurnInPlaceState.ActivationDelay = 0.0f; |
| 1938 | return; |
| 1939 | } |
| 1940 | |
| 1941 | TurnInPlaceState.ActivationDelay = TurnInPlaceState.ActivationDelay + GetDeltaSeconds(); |
| 1942 | |
| 1943 | const auto ActivationDelay{ |
| 1944 | FMath::GetMappedRangeValueClamped({Settings->TurnInPlace.ViewYawAngleThreshold, 180.0f}, |
| 1945 | Settings->TurnInPlace.ViewYawAngleToActivationDelay, |
| 1946 | FMath::Abs(ViewState.YawAngle)) |
| 1947 | }; |
| 1948 | |
| 1949 | // Check if the activation delay time exceeds the set delay (mapped to the view yaw angle). If so, start a turn in place. |
| 1950 | |
| 1951 | if (TurnInPlaceState.ActivationDelay <= ActivationDelay) |
| 1952 | { |
| 1953 | return; |
| 1954 | } |
| 1955 | |
| 1956 | // Select settings based on turn angle and stance. |
| 1957 | |
| 1958 | const auto bTurnLeft{UAlsRotation::RemapAngleForCounterClockwiseRotation(ViewState.YawAngle) <= 0.0f}; |
| 1959 | |
| 1960 | UAlsTurnInPlaceSettings* TurnInPlaceSettings{nullptr}; |
| 1961 | FName TurnInPlaceSlotName; |
nothing calls this directly
no outgoing calls
no test coverage detected