Skip to content
Snippets Groups Projects
Commit 30893e87 authored by David Gilbert's avatar David Gilbert :bug:
Browse files

Merge branch 'hotfix/turn_component' into 'dev/5.4'

TurnComponent Rotation Pivot Fix

See merge request !99
parents 33b4f6b2 ae7aecf7
Branches
Tags
1 merge request!99TurnComponent Rotation Pivot Fix
Pipeline #450198 passed
......@@ -4,6 +4,7 @@
#include "Pawn/Navigation/TurnComponent.h"
#include "EnhancedInputComponent.h"
#include "Camera/CameraComponent.h"
#include "Pawn/RWTHVRPawn.h"
#include "Utility/RWTHVRUtilities.h"
......@@ -110,15 +111,14 @@ void UTurnComponent::OnBeginSnapTurn(const FInputActionValue& Value)
void UTurnComponent::RotateCameraAndPawn(float Yaw) const
{
const FVector OrigLocation = VRPawn->GetActorLocation();
FVector PivotPoint = VRPawn->GetActorTransform().InverseTransformPosition(OrigLocation);
PivotPoint.Z = 0.0f;
const FVector OrigLocation = VRPawn->HeadCameraComponent->GetComponentLocation();
const FRotator OrigRotation = VRPawn->GetActorRotation();
const FRotator NewRotation = FRotator(0, VRPawn->GetActorRotation().Yaw + Yaw, 0);
const FVector NewLocation = OrigLocation + OrigRotation.RotateVector(PivotPoint);
const FVector Offset = VRPawn->GetActorLocation() - OrigLocation;
const FVector UntwistedOffset = OrigRotation.GetInverse().RotateVector(Offset);
const FVector NewLocation = OrigLocation + NewRotation.RotateVector(UntwistedOffset);
VRPawn->Controller->SetControlRotation(NewRotation);
VRPawn->SetActorLocationAndRotation(NewLocation, NewRotation);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment