Skip to content

Instantly share code, notes, and snippets.

@sarah-j-smith
Created July 24, 2025 02:26
Show Gist options
  • Save sarah-j-smith/1376f6d5beb9953b59ba22d72dbf575f to your computer and use it in GitHub Desktop.
Save sarah-j-smith/1376f6d5beb9953b59ba22d72dbf575f to your computer and use it in GitHub Desktop.
Flip a 2D character based on movement
// 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