Client Kart not moving on server solution

Took me a bit to figure this out, but I found that if you try to pass action input value directly it doesnt get sent to client. So I had to change the delcaration in the header and implement the cpp with the below. FVector2D is used because I am setting this up with standard wsad movement via IMC. Meaning the input is mapped as a 2d axis input(no Z axis). Also setting up the keys with swizzle axis input and negates for the approprait keys, you can look that the documentation to see how to handle it.

Header:
/** Called for movement input to server */

UFUNCTION(Server, Reliable, WithValidation)

void Server_Move(FVector2D MovementVector);

/** Called for movement input to local*/

void Move(const FInputActionValue& Value);

CPP:
void AGoKart::Move(const FInputActionValue &Value)

{

FVector2D MovementVector = Value.Get<FVector2D>();

if (Controller != nullptr)

{  

    //Sets the user input to forward amount of Y axis and roational amount in right/left with X axis

    Throttle = MovementVector.Y;

    SteeringThrow = MovementVector.X;

    Server_Move(MovementVector);

}

}

void AGoKart::Server_Move_Implementation(FVector2D MovementVector)

{

if (Controller != nullptr)

{  

    //Sets the user input to forward amount of Y axis and roational amount in right/left with X axis

   

    Throttle = MovementVector.Y;

    GEngine->AddOnScreenDebugMessage(-1,5,FColor::Blue,FString::Printf(TEXT("Throttle: %f"), Throttle));

    SteeringThrow = MovementVector.X;

}

}

bool AGoKart::Server_Move_Validate(FVector2D MovementVector)

{

return (FMath::Abs(MovementVector.X) <= 1 && FMath::Abs(MovementVector.Y) <=1);

//return true;

}

side note: if you use add movement input i beleive it already replicates on the server and client without having to add anything, but since I am trying to match the way movement is handled with IMC and the new action input system, you will need to replicate the movement, translation and rotation which is covered in a later lecture. So for now this should get you going in 5.1.

2 Likes

thanks for your sharing,it help me.

Privacy & Terms