Hi guys,
I am trying to create a simple hitscan weapon, but the line traces hit everything but other players.
I have a single AActor extension in C++, Afpscharacter, and a BP extension - BP_Fpscharacter, and these are for all the player characters in the game.
When I shoot a line trace multi by channel, the trace does not register overlaps with any player characters of the class mentioned above, and it seems not to register overlaps with anything (myself, or the enemy I am aiming at). Blocking hits from other actors do register, but I cannot test shooting at another player actor with these settings as enabling block on the player causes all shots to be stopped by the firing player’s own body, even with AddIgnoredActor(this) or AddIgnoredActor(GetOwner())
I have checked and all objects tested for overlap have Overlap collision enabled for visibility trace responses, and have ‘Generate Overlap events’ ticked, in their blueprints. I have played around with the capsule component and character mesh settings for overlapping, but no settings are working.
Eventually I would like to have it so that the rays collide with specific parts of the player mesh rather than just the capsule component (to implement head, body, leg shots etc).
Here is my code for the line trace:
bool Afpscharacter::MultiRaycastInCameraDirection(TArray<FHitResult>& ResultOutHit, float RaycastRange, ECollisionChannel CollisionChannel)
{
//Start coordinates are in FPS camera
FVector Start = FPSCameraComponent->GetComponentLocation();
//Gets direction player is looking at
FVector ForwardVector = FPSCameraComponent->GetForwardVector();
//End coordinate is range away from start
FVector End = Start + (ForwardVector * RaycastRange);
FCollisionQueryParams CollisionParams;
//Ignore ourselves
//CollisionParams.AddIgnoredComponent(GetCapsuleComponent());
CollisionParams.bReturnPhysicalMaterial = true;
//UE_LOG(LogTemp, Warning, TEXT("The Actor's name is %s"), *GetOwner()->GetName());
//UE_LOG(LogTemp, Warning, TEXT("Th name is %s"), *GetName());
DrawDebugLine(
GetWorld(),
FPSCameraComponent->GetComponentLocation(),
End,
FColor(255, 0, 0),
false, 5.0f, 0,
12.333
);
//Performs raycast
return GetWorld()->LineTraceMultiByChannel(ResultOutHit, Start, End, CollisionChannel, CollisionParams);
}
Here is my code for actually calling the above function (the channel defaults to ECC_Visibility due to header declaration)
//Here is where we actually perform the hitscan to see if we hit anything.
TArray<FHitResult> HitResults;
if (MultiRaycastInCameraDirection(HitResults, GetCurrentlyEquippedWeaponData().MaxRange))
{
//If we score a hit we must look at all the hit results and create hit markers and sound fx and stuff and deal dmg
UE_LOG(LogTemp, Warning, TEXT("Got a hit"));
}
Any help would be greatly appreciated. Thank you.