So I’m trying to make a multiplayer game and I’ve come to this next problem: for each player I want to check whether they are standing on safe area (ground actor tagged with ‘SafeArea’) or in the lava (landscape actor tagged with ‘UnsafeArea’). I wanted to perform the LineTraceByChannel
on the server and if player is in lava reduce health, which in turn would be replicated down to the client. However I came across a problem, the line-trace on the server doesn’t yield a consistent result, while doing the same on clients seems to always perform a correct line-trace. Is there some tweaking I need to do to make it work on the server? or should I leave it to the client (doesn’t this in turn ease up the cheating)?
here is a code sample:
p.s PRINT is just a macro for onscreen debug message
void AMyCharacter::Tick(float DeltaTime) {
FHitResult Hit;
FVector Start = GetActorLocation();
FVector End = GetActorLocation();
Start.Z += 100.f;
End.Z -= 300.f;
FCollisionQueryParams P;
P.AddIgnoredActor(this);
if (GetWorld()->LineTraceSingleByChannel(Hit, Start, End, ECC_WorldStatic, P))
{
if (HasAuthority())
{
if (Hit.GetActor()->Tags.Contains(FName("SafeArea")))
{
PRINT("Server: On Safe Ground")
}
else if (Hit.GetActor()->Tags.Contains(FName("UnsafeArea")))
{
PRINT("Server: In Lava")
}
}
else
{
if (Hit.GetActor()->Tags.Contains(FName("SafeArea")))
{
PRINT("Client: On Safe Ground")
}
else if (Hit.GetActor()->Tags.Contains(FName("UnsafeArea")))
{
PRINT("Client: In Lava")
}
}
}
With this code, while a player is in the safe area, the authoritative part sometimes goes in the if case and sometime in else-if, however the non-authoritative part always prints “Client: On Safe Ground”