Skip to content
Snippets Groups Projects
Commit 137fb007 authored by Kris Tabea Helwig's avatar Kris Tabea Helwig
Browse files

fix(movement): causes the pawn to rotate around its camera component instead of itself

parent 33b4f6b2
Branches
No related tags found
1 merge request!99TurnComponent Rotation Pivot Fix
Pipeline #444150 failed
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "Pawn/Navigation/TurnComponent.h" #include "Pawn/Navigation/TurnComponent.h"
#include "EnhancedInputComponent.h" #include "EnhancedInputComponent.h"
#include "Camera/CameraComponent.h"
#include "Pawn/RWTHVRPawn.h" #include "Pawn/RWTHVRPawn.h"
#include "Utility/RWTHVRUtilities.h" #include "Utility/RWTHVRUtilities.h"
...@@ -110,15 +111,14 @@ void UTurnComponent::OnBeginSnapTurn(const FInputActionValue& Value) ...@@ -110,15 +111,14 @@ void UTurnComponent::OnBeginSnapTurn(const FInputActionValue& Value)
void UTurnComponent::RotateCameraAndPawn(float Yaw) const void UTurnComponent::RotateCameraAndPawn(float Yaw) const
{ {
const FVector OrigLocation = VRPawn->GetActorLocation(); const FVector OrigLocation = VRPawn->HeadCameraComponent->GetComponentLocation();
FVector PivotPoint = VRPawn->GetActorTransform().InverseTransformPosition(OrigLocation);
PivotPoint.Z = 0.0f;
const FRotator OrigRotation = VRPawn->GetActorRotation(); const FRotator OrigRotation = VRPawn->GetActorRotation();
const FRotator NewRotation = FRotator(0, VRPawn->GetActorRotation().Yaw + Yaw, 0); 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->Controller->SetControlRotation(NewRotation);
VRPawn->SetActorLocationAndRotation(NewLocation, 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