I’m stumped on this one, can’t for the life of me figure it out. When my vehicles are killed or if a player ‘bails out’, a new Pilot (character) is spawned and immediatelly possesed by the player. Upon spawn (server side only, ofc), I call ‘Launch Character’ to give them some ejection velocity.
This works absolutely fine for the player on the Server. For whatever reason though, I can’t for the life of me get the **** thing to work for Clients. Surely, the logic is correct?
void ABZGame_Vehicle::ServerEjectPilot_Implementation(bool bBailout)
{
const FTransform SpawnTransform = FTransform(FRotator(0.f, GetVehicleMesh()->GetComponentRotation().Yaw, 0.f), FVector(GetVehicleMesh()->GetComponentLocation() + FRotator(GetActorRotation()).RotateVector(PilotEjectLocation)));
FActorSpawnParameters SpawnParams;
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
SpawnParams.Owner = GetController();
ABZGame_Character* NewPilot = GetWorld()->SpawnActor<ABZGame_Character>(DefaultPilot, SpawnTransform, SpawnParams);
ASSERTV(NewPilot != nullptr, *FString::Printf(TEXT("Unable To Spawn Pilot for %s"), *GetNameSafe(this)));
APlayerController* MyPC = Cast<APlayerController>(GetController());
if (MyPC)
{
MyPC->Possess(NewPilot);
}
else
{
NewPilot->SpawnDefaultController();
}
bHasPilot = false;
bPilotWantsToExit = false;
const FVector EjectVelocity = FRotator(GetActorRotation()).RotateVector(bBailout ? PilotBailoutVelocity : PilotHopoutVelocity);
NewPilot->LaunchCharacter(EjectVelocity, true, true);
}
This all happens Server-Side, and the player ejects perfectly fine for the Server Player, but NOT for client players (on the Server or otherwise). I want to launch the character on the Server and rely on movement replication to pass that down to the clients.
On the flipside, I’m experiencing a second issue where applying a ‘Force’ to Characters on the Client side is for some reason doubled in size. I have Jetpack item which simply applies force while the Jetpack is firing. On the Server, the force is correct - but on the Client, the character is launched over twice the distance.
Any ideas?
void ABZGame_JetPack::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
if (bJetpackFiring && UpdatedCharacter && Role == ROLE_Authority)
{
BurnDuration += DeltaSeconds;
const float MappedCurveTime = FMath::GetMappedRangeValueClamped(FVector2D(0.f, JetpackData.BurnTime), FVector2D(0.f, 1.f), BurnDuration);
UseAmmo(OrdnanceCost * DeltaSeconds);
const FVector JetpackForce = ImpartedLaunchDirection * JetpackData.ThrustCurve->GetFloatValue(MappedCurveTime);
UpdatedCharacter->GetCharacterMovement()->AddForce(JetpackForce);
}
}