Skip to content

Turn

Overview

  • Rotates a character based on a 2D Input Value.
  • By default, it's connected to the IA_Turn input.
  • Handles Triggered and Ongoing events.
  • Supports blocking the rotation, via the presence of Gameplay Tags.
  • Mostly meant to be used as the right gamepad thumbstick for top-down movement.

Handling the Rotation With the Mouse

Right now, there are some complexities in handling rotation with the Mouse, using the Enhanced Input System structure. Even though we could track ongoing mouse movement and feed that into the character, that only works when the mouse cursor is not being displayed. If it is, then the engine captures the mouse and handles the event before it reaches the Enhanced Input.

The best way to rotate the character in a Top-Down setup, using the mouse, is to implement that functionality in the APlayerController class, in the Tick function. This is a starting point:

void AMyPlayerController::Tick(float DeltaSeconds)
{
    FHitResult YawHit;
    if (GetHitResultUnderCursorByChannel(UEngineTypes::ConvertToTraceType(MouseChannel), true, YawHit) && YawHit.bBlockingHit)
    {
        const FVector SourceLocation = MyPawn->GetActorLocation();
        const FVector TargetLocation = YawHit.Location;

        FRotator DesiredRotation = UKismetMathLibrary::FindLookAtRotation(SourceLocation, TargetLocation);
        DesiredRotation.Roll = 0.f;

        SetControlRotation(UKismetMathLibrary::RInterpTo(GetControlRotation(), DesiredRotation,
            GetWorld()->GetDeltaSeconds(), RotateSpeed));
    }
}

Controller Rotation