Reputation: 13
i tried to make movement functions with RPC.
And the movement functions, is binded with EnhancedInput->BindAction.
void AGoKartPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
UE_LOG(LogTemp, Warning, TEXT("Setup Player Input Component"));
Super::SetupPlayerInputComponent(PlayerInputComponent);
UEnhancedInputComponent* EnhancedInput = Cast<UEnhancedInputComponent>(InputComponent);
if (EnhancedInput == nullptr) return;
EnhancedInput->BindAction(AccelerateAction, ETriggerEvent::Triggered, this, &AGoKartPawn::Server_Accelerate);
EnhancedInput->BindAction(AccelerateAction, ETriggerEvent::Completed, this, &AGoKartPawn::ClearAccelerate);
EnhancedInput->BindAction(TurnAction, ETriggerEvent::Triggered, this, &AGoKartPawn::TurnRight);
EnhancedInput->BindAction(TurnAction, ETriggerEvent::Completed, this, &AGoKartPawn::ClearTurning);
}
As i want to make it multiplay game, i did declared Accelerate function as RPC.
UFUNCTION(Server, Reliable, WithValidation)
void Server_Accelerate(const FInputActionValue& Value);
So there are Implement and Validate functions.
void AGoKartPawn::Server_Accelerate_Implementation(const FInputActionValue& Value)
{
UE_LOG(LogTemp, Warning, TEXT("Accelerating"));
// 1 or 0
float IsAccelerating = Value.Get<float>();
Accelerating = IsAccelerating;
}
bool AGoKartPawn::Server_Accelerate_Validate(const FInputActionValue& Value)
{
return FMath::Abs(Value.Get<float>()) <= 1;
}
But the problem is, server pawn's movement is fine but client pawn doesn't move at all both on server and client.
I expected that after the player input keys, client pawn move upon the server's movement decision by the RPC movement function based on such key input.
But I can't find any other references like using RPC in Enhanced Input.
if there are other ways to Enhanced Input System can multiplay, please let me know.
Thanks for your help :D
Upvotes: 0
Views: 95