I’m trying to apply VRRoot to my multiplayer project.
This is my code.
BP_VRCharacter
VRCharacter.h
void CalculateHMDToCharLocation();
void HMDSyncLocation();
UFUNCTION(Server, Unreliable)
void Server_HMDSyncLocation(FVector NewLocation);
FVector HMDToCharLocation = FVector::ZeroVector;
VRCharacter.cpp
void AVRCharacter::Tick(float DeltaTime)
{
CalculateHMDToCharLocation();
HMDSyncLocation();
Super::Tick(DeltaTime);
}
void AVRCharacter::CalculateHMDToCharLocation()
{
FVector NewCameraOffset = Camera->GetComponentLocation() - GetActorLocation();
NewCameraOffset.Z = 0;
HMDToCharLocation = NewCameraOffset;
Server_HMDSyncLocation(NewCameraOffset);
}
void AVRCharacter::HMDSyncLocation()
{
AddActorWorldOffset(HMDToCharLocation);
VRRoot->AddWorldOffset(-HMDToCharLocation);
}
void AVRCharacter::Server_HMDSyncLocation_Implementation(FVector NewLocation)
{
HMDToCharLocation = NewLocation;
}
I didn’t understand the multiplayer lecture well, but I wrote the code with my stupid brain.
It works when playing Play as Client with two players, but there is jittering.
The client (Client 0) that moves the HMD moves with jittering,
but client 1 looking at it seems to be moving well.
I’ve been thinking about solving this problem for two days, but I can’t.
Any advice will be appreciated. Help me…