Hello guys! For days I’m trying to figure out how replication works. I’ve watched lots of tutorials and read the docs but It’s a mess in my head.
So for example now I’m trying to fly around with a dragon, so I’m using a Pawn and I had to replicate the movement. I’m using the mouse to look around and currently I have only this scenario.
Server → Can fly / rotate
Client 1 → Can see the server flying/rotate. Can’t rotate only flying forward.
Client 2 → Can see the server flying/rotate. Can’t rotate only flying forward + it’s rotation when I control the server (Half of rotations).
As I understood what I need to do is.
- Send rotation to server
- From server send back to the pawn the rotation data.
Here I can’t understand how this things works. I currently have this.
Pawn.cpp
void ADragonPawn::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
Flying(DeltaTime);
APlayerController* MyPC = Cast<APlayerController>(GetController());
if(MyPC)
{
FVector ScreenMouseLocation, ScreenMouseDirection;
MyPC->DeprojectMousePositionToWorld(ScreenMouseLocation, ScreenMouseDirection);
ScreenMouseDirection = ScreenMouseDirection * 5000000.0f;
FVector MouseWorldSpace = ScreenMouseLocation + ScreenMouseDirection;
FlyingRotation(MouseWorldSpace,ScreenMouseLocation,ScreenMouseDirection);
}
}
void ADragonPawn::Flying(float DeltaTime)
{
FlyingSpeed = UKismetMathLibrary::FInterpTo(FlyingSpeed, FlyingSpeedTarget, DeltaTime, AccelerationSpeed);
ForwardFly.X = FlyingSpeed;
AddActorLocalOffset(ForwardFly);
}
void ADragonPawn::FlyingRotation(FVector MouseWorldSpace, FVector ScreenMouseLocation, FVector ScreenMouseDirection)
{
S_ServerRotation(MouseWorldSpace,ScreenMouseLocation,ScreenMouseDirection);
}
void ADragonPawn::S_ServerRotation_Implementation(FVector MouseWorldSpace, FVector ScreenMouseLocation, FVector ScreenMouseDirection)
{
FRotator LookAtRot = UKismetMathLibrary::FindLookAtRotation(this->GetActorLocation(),MouseWorldSpace);
FRotator NewPlayerRot = FRotator (LookAtRot.Pitch, LookAtRot.Yaw,0.0f);
if(NewPlayerRot.Pitch >= 75)
{
NewPlayerRot.Pitch = 75;
}
else if(NewPlayerRot.Pitch < -75)
{
NewPlayerRot.Pitch = -75;
}
PawnDirection = UKismetMathLibrary::RInterpTo(this->GetActorRotation(), NewPlayerRot, 1, 0.08f);
SetActorRotation(PawnDirection);
ClienRotation = PawnDirection;
OnRep_SetRotation();
}
bool ADragonPawn::S_ServerRotation_Validate(FVector MouseWorldSpace, FVector ScreenMouseLocation, FVector ScreenMouseDirection)
{
return true;
}
void ADragonPawn::OnRep_SetRotation()
{
SetActorRotation(ClienRotation);
}
This is not working as expected and I really don’t know how to make it work.
Thank you