So I have been searching for hours now but could not find a solution to this and replication still confuses me a bit, especially in C++.
I want my Characters to be able to apply damage to eachother but this only works from server to client so how can I get this to work in the opposite direction?
My code right now (a bit condensed):
ADevCharacter.h:
public:
UPROPERTY(Replicated)
float Health;
ADevCharacter.cpp:
void ADevCharacter::Fire() {
FCollisionQueryParams RV_TraceParams = FCollisionQueryParams(FName(TEXT("RV_Trace")), true, this);
RV_TraceParams.bTraceComplex = true;
RV_TraceParams.bTraceAsyncScene = true;
RV_TraceParams.bReturnPhysicalMaterial = false;
FHitResult RV_Hit(ForceInit);
FVector Start = this->GetActorLocation();
FVector End = (this->GetActorForwardVector() * 300.f) + this->GetActorLocation();
bool isHit = GetWorld()->LineTraceSingleByObjectType(RV_Hit, Start, End, ECC_Pawn, RV_TraceParams);
DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 1, 0, 5);
TSubclassOf<UDamageType> P;
ADevCharacter* HitChar = Cast<ADevCharacter>(RV_Hit.GetActor());
if (isHit) {
FPointDamageEvent* DamageEvent = new FPointDamageEvent();
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("HIT"));
UGameplayStatics::ApplyPointDamage(HitChar,10.f, this->GetActorForwardVector(),RV_Hit, this->GetController(), this, P);
}
}
float ADevCharacter::TakeDamage(float DamageAmount, FDamageEvent const &DamageEvent, AController *EventInstigatior, AActor *DamageCauser) {
Health -= DamageAmount;
if (Health < 0) {
AWarPlayerController* PlayerController = Cast<AWarPlayerController>(Controller);
if (PlayerController) {
PlayerController->OnKilled();
Destroy();
}
}
return DamageAmount;
}