From 3d6624324e285dc3f82603bcc50153119dbaedf5 Mon Sep 17 00:00:00 2001 From: ameaninglessname Date: Tue, 4 Oct 2022 16:09:30 +0800 Subject: [PATCH] Temporary code for debugging https://github.com/dyanikoglu/ALS-Community/issues/258 shaking tool problem: DedicatedServer rotation is driven by client RPC now, because curve driven rotation is only available when VisibilityBasedAnimTickOption is set to AlwaysTickPoseAndRefreshBones(AFAIK), so we need a more general approach. (it's a naive approach but should be enough for debugging, for a formal solution see CallServerMovePacked, FCharacterNetworkMoveData) --- .../Private/Character/ALSBaseCharacter.cpp | 24 +++++++++++++------ .../Public/Character/ALSBaseCharacter.h | 3 +++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp b/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp index 5b859abe..0d57962f 100644 --- a/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp +++ b/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp @@ -1057,6 +1057,12 @@ void AALSBaseCharacter::UpdateGroundedRotation(const float DeltaTime) } else { + if (IsNetMode(NM_DedicatedServer)) + { + // DedicatedServer rotation is driven by client RPC + return; + } + if (GetLocalRole() == ROLE_SimulatedProxy) { // const FScopedPreventAttachedComponentMove PreventMeshMove(GetMesh()); @@ -1079,15 +1085,13 @@ void AALSBaseCharacter::UpdateGroundedRotation(const float DeltaTime) if (const float RotAmountCurve = GetAnimCurveValue(NAME_RotationAmount); FMath::Abs(RotAmountCurve) > 0.001f) { + TargetRotation.Yaw = UKismetMathLibrary::NormalizeAxis( + TargetRotation.Yaw + (RotAmountCurve * (DeltaTime / (1.0f / 30.0f)))); + SetActorRotation(TargetRotation); + if (GetLocalRole() == ROLE_AutonomousProxy) { - TargetRotation.Yaw = UKismetMathLibrary::NormalizeAxis( - TargetRotation.Yaw + (RotAmountCurve * (DeltaTime / (1.0f / 30.0f)))); - SetActorRotation(TargetRotation); - } - else - { - AddActorWorldRotation({0, RotAmountCurve * (DeltaTime / (1.0f / 30.0f)), 0}); + Server_SetActorRotation(TargetRotation); } TargetRotation = GetActorRotation(); } @@ -1105,6 +1109,12 @@ void AALSBaseCharacter::UpdateGroundedRotation(const float DeltaTime) // Other actions are ignored... } +void AALSBaseCharacter::Server_SetActorRotation_Implementation(const FRotator Rotator) +{ + TargetRotation = Rotator; + SetActorRotation(Rotator); +} + void AALSBaseCharacter::UpdateInAirRotation(const float DeltaTime) { if (RotationMode == EALSRotationMode::VelocityDirection || RotationMode == EALSRotationMode::LookingDirection) diff --git a/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h b/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h index 8cd431c2..d36c08d9 100644 --- a/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h +++ b/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h @@ -388,6 +388,9 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter void UpdateGroundedRotation(float DeltaTime); + UFUNCTION(Server, Reliable) + void Server_SetActorRotation(const FRotator Rotator); + void UpdateInAirRotation(float DeltaTime); /** Utils */