From 75b578cad14a69ec1527aeb2c17c859291da96fd Mon Sep 17 00:00:00 2001
From: David Gilbert <gilbert@vr.rwth-aachen.de>
Date: Wed, 19 Mar 2025 15:43:56 +0100
Subject: [PATCH] fix(replication): Makes ClientTransformReplication use
 relative position and rotation.

---
 .../Private/Core/ClientTransformReplication.cpp              | 4 ++--
 .../RWTHVRToolkit/Public/Core/ClientTransformReplication.h   | 5 ++++-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/Source/RWTHVRToolkit/Private/Core/ClientTransformReplication.cpp b/Source/RWTHVRToolkit/Private/Core/ClientTransformReplication.cpp
index 0bce9302..011c8337 100644
--- a/Source/RWTHVRToolkit/Private/Core/ClientTransformReplication.cpp
+++ b/Source/RWTHVRToolkit/Private/Core/ClientTransformReplication.cpp
@@ -26,8 +26,8 @@ void UClientTransformReplication::UpdateState(float DeltaTime)
 		// Only do this if we actually replicate the actor
 		if (GetIsReplicated())
 		{
-			const FVector Loc = OwningActor->GetActorLocation();
-			const FRotator Rot = OwningActor->GetActorRotation();
+			const FVector Loc = OwningActor->GetRootComponent()->GetRelativeLocation();
+			const FRotator Rot = OwningActor->GetRootComponent()->GetRelativeRotation();
 
 			// Only update state if the local state changed
 			if (!Loc.Equals(ReplicatedTransform.Position) || !Rot.Equals(ReplicatedTransform.Rotation))
diff --git a/Source/RWTHVRToolkit/Public/Core/ClientTransformReplication.h b/Source/RWTHVRToolkit/Public/Core/ClientTransformReplication.h
index ac364067..c31ed9bd 100644
--- a/Source/RWTHVRToolkit/Public/Core/ClientTransformReplication.h
+++ b/Source/RWTHVRToolkit/Public/Core/ClientTransformReplication.h
@@ -56,7 +56,10 @@ protected:
 		// For now, directly apply the transforms:
 		auto* OwningActor = GetOwner();
 		if (OwningActor && OwningActor->HasValidRootComponent())
-			OwningActor->SetActorLocationAndRotation(ReplicatedTransform.Position, ReplicatedTransform.Rotation);
+		{
+			OwningActor->SetActorRelativeLocation(ReplicatedTransform.Position);
+			OwningActor->SetActorRelativeRotation(ReplicatedTransform.Rotation);
+		}
 	}
 
 	// Unreliable Server RPC that sends the transform from owning client to the server
-- 
GitLab