Rpc is working, but rotation on client is lagging. i know, may be this code is weird but i am very new to c++.
void AHalfDeadCharacter::ChangeCamera()
{
if (IsDefaultCamera == true) {
FollowCamera->Deactivate();
FirstPersonCamera->Activate();
IsDefaultCamera = false;
}
else {
FollowCamera->Activate();
FirstPersonCamera->Deactivate();
IsDefaultCamera = true;
}
}
void AHalfDeadCharacter::SetFirstPerson(AHalfDeadCharacter* Player1)
{
if (Player1->IsDefaultCamera == false) {
Player1->CharacterRotation = (FRotator(0.f, Player1->FirstPersonCamera->GetComponentRotation().Yaw, Player1->GetActorRotation().Roll));
Player1->SetActorRotation(Player1->CharacterRotation);
if (Player1->HasAuthority() == false) {
Server_SetFirstPerson(Player1);
}
}
}
void AHalfDeadCharacter::Server_SetFirstPerson_Implementation(AHalfDeadCharacter* Player)
{
Player->SetActorRotation(Player->CharacterRotation);
Player->CharacterRotation = (FRotator(0.f, Player->FirstPersonCamera->GetComponentRotation().Yaw, Player->GetActorRotation().Roll));
if (this->GetActorRotation() != Player->CharacterRotation) {
this->SetActorRotation(Player->CharacterRotation);
if (this->GetActorRotation() != Player->CharacterRotation) {
this->SetActorRotation(Player->CharacterRotation);
}
}
}
bool AHalfDeadCharacter::Server_SetFirstPerson_Validate(AHalfDeadCharacter* Player)
{
return true;
}
void AHalfDeadCharacter::GetLifetimeReplicatedProps(TArray< FLifetimeProperty >& OutLifetimeProps) const {
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(AHalfDeadCharacter, CharacterRotation);
}
void AHalfDeadCharacter::Tick(float DeltaTime)
{
SetFirstPerson(this);
}
i tried different variations of replication First Person Rotation, but i dont think i should share this expirience.