Created
July 24, 2025 02:26
-
-
Save sarah-j-smith/1376f6d5beb9953b59ba22d72dbf575f to your computer and use it in GitHub Desktop.
Flip a 2D character based on movement
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Credit: https://www.youtube.com/watch?v=ogIyMrX_uws&t=1079s | |
| UCharacterMovementComponent *MovementComponent = GetCharacterMovement(); | |
| FVector Velocity = MovementComponent->Velocity; | |
| FRotator CurrentRotation = Controller->GetControlRotation(); | |
| if (Velocity.X > 0) | |
| { | |
| if (!CurrentRotation.Pitch == 0.0) | |
| { | |
| FRotator NewRotation = CurrentRotation; | |
| NewRotation.Pitch = 0.0f; | |
| Controller->SetControlRotation(NewRotation); | |
| } | |
| } | |
| else | |
| { | |
| if (!CurrentRotation.Pitch == 180.0) | |
| { | |
| FRotator NewRotation = CurrentRotation; | |
| NewRotation.Pitch = 180.0f; | |
| Controller->SetControlRotation(NewRotation); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment