AimOffset Pitch in multiplayer

Oh, ok, thanks. I just thought that it might be in an intermediate update(like 4.3.1 or 4.2.1)

Here is the solution for C++ multiplayer, but please help and describe the math, I would really appreciate that!


void ACPP_1Character::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);
    if (!IsLocallyControlled()) {
        FRotator NewRot = FirstPersonCameraComponent->RelativeRotation;
        NewRot.Pitch = (uint8)RemoteViewPitch * 360.f / 255.f; // to compress to 1 byte [edited to help others]

        FirstPersonCameraComponent->SetRelativeRotation(NewRot);
    }
}

But please explain me why do use this math

And if I am right this one:

, is used to not do for you character, because you do not need it, and it is already happening or not?

I only catch on 360°(degrees), and 255 is the limitation of uint8

Why is RemoteViewPitch is 255 only instaed of 360 (to save some memory or what?)

RemoteViewPitch is replicated in a byte (0-255) to save on replication bandwidth (though this is less of a concern these days). This code looks like it says for non-local characters, you need to set the rotation of the camera, and you do that by remapping the byte to a 360 degree value. Reorder the statement to ((float)RemoteViewPitch / 255.f) * 360.f and it might make more sense. Map to (0…1), then scale to (0…360).

See APawn::GetBaseAimRotation() and APawn::SetRemoteViewPitch().

Hello Zak,

Thank you so much for your answer and the other posts!

One more Solution(with your help):


void ACPP_1Character::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);
    if (!IsLocallyControlled()) {
        FRotator NewRot = FirstPersonCameraComponent->RelativeRotation;
        NewRot.Pitch = (float)(GetBaseAimRotation().Pitch);

        FirstPersonCameraComponent->SetRelativeRotation(NewRot);
    }
}

[HR][/HR]
**I have found your replies in this post, which was really helpful to get more into this topic:
URL link to the post: Serious shot replication problem [video] with more info about ViewPitch + **GetBaseAimRotation

[QUESTION 1]
How is the clients’ pitch is replicated?

But could you please clarify a bit about how the replication is done( I have read the post above, but that does not suffice for me to get how it works)?
So e.g.
I used next construction:


if(Role == ROLE_Authority) { // some actions which you need to replicate(run on server and tell your clients) }

[QUESTION 2]
One more thing I would like to know:
Why the yaw is already being replicated by default, but the pitch is not? (Sorry if I misread somewhere and did not notice this) [HR][/HR]

Best regards,
Roman!

Replication happens for Actors by looking at what properties to replicate, given by GetLifetimeReplicatedProps(). Pawn marks RemoteViewPitch as Replicated in its UPROPERTY definition and says to replicate it in the mentioned function to everyone but the owner (COND_SkipOwner, because they sent the value to the server already).

Normally Actors replicate their complete actor rotation if they are set to replicate, and this is the case for Pawns as well. However for Pawns/Characters we usually don’t tilt the capsule upward, but they do spin around horizontally on the vertical axis. However we still want to know which way they are looking/aiming, so RemoteViewPitch is replicated additionally as a variable on the Pawn. If this setup didn’t work well for a specific project, an alternative would be to replicate your own variable(s) that replicated more of what you need, like all of ControlRotation etc.

Thank you, Sir, again! :slight_smile:

I do appreciate you help!

I have already fiddle with GetLifetimeReplicatedProps() a bit.

Please, if you have some free time take a glance at my new [url: [question](Can not get game state inside of Game Mode "cannot convert argument 1 from 'From *' to 'UObject *'" - C++ Gameplay Programming - Unreal Engine Forums)] – (***Solved ***[I have derived from the wrong class])

Could someone please explain or direct where I can find what have I done wrong?
Pitch replication works just fine if I Set 2 players(server and client can see each other pitch rotation), but if I run it as a standalone game it does not work…

this code it run



// Called every frame
void ASCharacter::Tick(float DeltaTime)
if (!IsLocallyControlled()) { // even if i try it like this: if (!IsLocallyControlled() || Role == ROLE_Authority)
        if (FPPCameraComp->IsActive()) {
            FRotator NewRot = FPPCameraComp->RelativeRotation;
            NewRot.Pitch = (uint8)RemoteViewPitch * 360.f / 255.f; // to compress to 1 byte [edited to help others]
            Pitch = NewRot.Pitch;
            FPPCameraComp->SetRelativeRotation(NewRot);
        }
        else if (CameraComp->IsActive()) {
            FRotator NewRot = CameraComp->RelativeRotation;
            NewRot.Pitch = (float)(GetBaseAimRotation().Pitch);
            Pitch = NewRot.Pitch;
            CameraComp->SetRelativeRotation(NewRot);
        }
    }
}


ScreenShots:
[SPOILER]

[/SPOILER]

My AnimBP “Pitch” value is set to Replicated

I greatly appreciate your help!