Download

Client/Server Block Placing Location/Rotation Replication Issue

https://www.youtube.com/watch?v=kfr-YIFRZ5w&feature=youtu.be

Ok, so everything is kind of working as planned on the server. But the client representation of where the placeholder block is located is skewed on the client, BUT the server will always maintain its actual position and rotation so that even when i place a block on the client, it will place it to where the server says it should be. I’ve tried using both Relative and World location but nothing made a difference.




BaseCharacter.h
-----------------------------------------------
public:
     UPROPERTY(EditAnywhere, Replicated)
     UStaticMeshComponent* BlockPlaceholder;

    void PlaceBlock();

protected:
    /* [Server] PlaceBlock */
    UFUNCTION(Reliable, Server, WithValidation)
    void ServerPlaceBlock();
    bool ServerPlaceBlock_Validate();
    void ServerPlaceBlock_Implementation();


BaseCharacter.cpp
-----------------------------------------------
FVector CamLoc;
FRotator CamRot;
Controller->GetPlayerViewPoint(CamLoc, CamRot);
FVector TraceEnd = CamLoc + CamRot.Vector() * BUILD_DISTANCE;
FHitResult Hit(ForceInit);

   /* [Server] PlaceBlock */
void ABaseCharacter::PlaceBlock()
{
    if (Role == ROLE_Authority)
    {

        FVector CamLoc;
        FRotator CamRot;
        Controller->GetPlayerViewPoint(CamLoc, CamRot);
        FVector TraceEnd = CamLoc + CamRot.Vector() * BUILD_DISTANCE;
        FCollisionQueryParams* TraceParams = new FCollisionQueryParams();
        FHitResult Hit(ForceInit);

        BlockPlaceholder->SetWorldLocationAndRotation(TraceEnd, GetActorRotation());

    }
    else
    {
        ServerRunBuildMode();
    }
}    
void ABaseCharacter::ServerPlaceBlock_Implementation()
{
    RunBuildMode();
}
bool ABaseCharacter::ServerPlaceBlock_Validate()
{
    return true;
}