In the video Unreal help - YouTube as you can see when I aim at the head, I hit the “upper arm” and on the server of my other player, you can see the debug line is hitting the head and is constantly moving because of the animation. How can I stop this from happening? The game is never consistent as to where I aim. For my player I have this : (so you can get a sense of how my components are created and what is attached to what)
AFPSCharacter::AFPSCharacter()
{
SetReplicates(true);
SetReplicateMovement(true);
FPSCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FPS Camera"));
FPSCamera->FieldOfView = 120;
FPSCamera->bUsePawnControlRotation = true;
FPSCamera->SetupAttachment(GetCapsuleComponent());
FPSCamera->AttachToComponent(GetMesh(), FAttachmentTransformRules::SnapToTargetNotIncludingScale, FName("head"));
FPSMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("FPSMesh"));
FPSMesh->SetupAttachment(FPSCamera);
FPSMesh->CastShadow = false;
FPSMesh->SetOnlyOwnerSee(true);
GetMesh()->SetOwnerNoSee(true);
GunMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Weapon Mesh"));
GunMesh->CastShadow = false;
GunMesh->SetupAttachment(FPSMesh, "GripPoint");
TPGunMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("TPGunMesh"));
TPGunMesh->SetupAttachment(GetMesh(), "WeaponSocket");
TPGunMesh->SetOwnerNoSee(true);
//getMesh() is essentially the third person mesh.
}
could it be the way I connected these components and its throwing off the line tracing causing the constant strafing that we see on the client?
for fire I call these:
void AFPSCharacter::Fire()
{
if (Item && Item->bPickedUp) {
if (GetLocalRole() < ROLE_Authority) {
ServerFire();
UE_LOG(LogTemp, Warning, TEXT("Fire"));
}
}
}
void AFPSCharacter::ServerFire_Implementation()
{
if (Item && Item->bPickedUp) {
if (GetLocalRole() == ROLE_Authority) {
NetFire();
UE_LOG(LogTemp, Warning, TEXT("Server Fire"));
}
}
}
bool AFPSCharacter::ServerFire_Validate()
{
return true;
}
void AFPSCharacter::NetFire_Implementation()
{
if (Item && Item->bPickedUp) {
Item->Fire();
UE_LOG(LogTemp, Warning, TEXT("NetFire"));
}
}
//item fire:
void AItem::Fire()
{
//following tom loomans tutorial of shooting!
FVector EyeLocation;
FRotator EyeRotation;
EyeLocation = FPSCharacterRef->GunMesh->GetSocketLocation("MuzzleFlash");
EyeRotation = FPSCharacterRef->GunMesh->GetSocketRotation("MuzzleFlash");
FVector ShotDirection = EyeRotation.Vector();
FVector TraceEnd = EyeLocation + (ShotDirection * 10000);
FHitResult Hit;
FCollisionQueryParams QueryParams;
QueryParams.AddIgnoredActor(this);
//QueryParams.AddIgnoredActor(FPSCharacterRef->GetOwner());
QueryParams.bTraceComplex = true;
if (GetWorld()->LineTraceSingleByChannel(Hit, EyeLocation, TraceEnd, ECC_Visibility, QueryParams)) {
AActor*HitActor = Hit.GetActor();
//if we hit a player we want to subtract the health from that player
UE_LOG(LogTemp, Warning, TEXT("%s"), *HitActor->GetName());
//if the hit actor IS an enemy player
UGameplayStatics::ApplyPointDamage(HitActor, DPS, ShotDirection, Hit, HitActor->GetInstigatorController(), this, DamageType);
}
DrawDebugLine(GetWorld(), EyeLocation, TraceEnd, FColor::Red, false, 1.0f, 0, 1.0f);
}
As you can see, it should be accurate everything is constant and im not sure why its so messed up. Some guidance would be nice, thank you