Skip to content

Instantly share code, notes, and snippets.

@theresajayne
Created January 22, 2019 09:34
Show Gist options
  • Save theresajayne/ff4351a6143d1045e712d5225698a8bf to your computer and use it in GitHub Desktop.
Save theresajayne/ff4351a6143d1045e712d5225698a8bf to your computer and use it in GitHub Desktop.
void ABaseCharacter::FireWeapon()
{
ABasePlayerController* controller = Cast<ABasePlayerController>(Controller);
if (!controller || !controller->IsGameInputAllowed())
return;
FHitResult OutHit;
FVector start = myCamera->GetComponentLocation();
FVector end = start + myCamera->GetForwardVector() * 100000.0f;
FCollisionQueryParams CollisionParams;
CollisionParams.AddIgnoredActor(this);
CollisionParams.AddIgnoredActor(myWeapon);
FCollisionResponseParams CollisionResponseParams;
if (GetWorld()->SweepSingleByChannel(OutHit, start, end, FQuat::Identity, ECollisionChannel::ECC_Visibility, FCollisionShape::MakeSphere(5.0f), CollisionParams, CollisionResponseParams))
myWeapon->Fire(OutHit.Location);
else
myWeapon->Fire(end);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment