本文整理汇总了C++中FHitResult::GetActor方法的典型用法代码示例。如果您正苦于以下问题:C++ FHitResult::GetActor方法的具体用法?C++ FHitResult::GetActor怎么用?C++ FHitResult::GetActor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FHitResult
的用法示例。
在下文中一共展示了FHitResult::GetActor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ProcessInstantHit_Confirmed
void AShooterWeapon_Instant::ProcessInstantHit_Confirmed(const FHitResult& Impact, const FVector& Origin, const FVector& ShootDir, int32 RandomSeed, float ReticleSpread)
{
// handle damage
if (ShouldDealDamage(Impact.GetActor()))
{
DealDamage(Impact, ShootDir);
}
// play FX on remote clients
if (Role == ROLE_Authority)
{
HitNotify.Origin = Origin;
HitNotify.RandomSeed = RandomSeed;
HitNotify.ReticleSpread = ReticleSpread;
}
// play FX locally
if (GetNetMode() != NM_DedicatedServer)
{
const FVector EndTrace = Origin + ShootDir * InstantConfig.WeaponRange;
const FVector EndPoint = Impact.GetActor() ? Impact.ImpactPoint : EndTrace;
SpawnTrailEffect(EndPoint);
SpawnImpactEffects(Impact);
}
}
示例2: CheckTraceDistance
void AKIMCharacter::CheckTraceDistance() {
if (IsInRoationState) {
return;
}
FHitResult outHit;
FCollisionQueryParams params;
params.AddIgnoredActor(this);
params.AddIgnoredActor(PickedUpItem);
FVector TraceStart = CameraComponent->GetComponentLocation();
FVector TraceEnd = TraceStart + (CameraComponent->GetForwardVector() * InteractionDistance);
GetWorld()->LineTraceSingleByChannel(outHit, TraceStart, TraceEnd, ECollisionChannel::ECC_PhysicsBody, params);
if (outHit.GetActor() != NULL && outHit.GetActor()->GetClass()->IsChildOf(AKIMInteractionActor::StaticClass())) {
if (((AKIMInteractionActor*)outHit.GetActor())->InteractionType != StoredType){
StoredType = ((AKIMInteractionActor*)outHit.GetActor())->InteractionType;
SwitchIconState(StoredType);
}
}
else {
if (StoredType != EKIMInteractionTypes::NONE) {
StoredType = EKIMInteractionTypes::NONE;
SwitchIconState(StoredType);
}
}
}
示例3: SpawnEffectOnHitLoc_Implementation
void UARFXEffectComponent::SpawnEffectOnHitLoc_Implementation(UParticleSystem* FXIn, FHitResult HitLocation, APawn* Causer)
{
if (!HitLocation.GetActor() && !FXIn)
return;
UParticleSystemComponent* ImpactPSC = UGameplayStatics::SpawnEmitterAtLocation(HitLocation.GetActor(), FXIn, HitLocation.ImpactPoint);
}
示例4: ProcessInstantHit
void AShooterWeapon_Instant::ProcessInstantHit(const FHitResult& Impact, const FVector& Origin, const FVector& ShootDir, int32 RandomSeed, float ReticleSpread)
{
if (MyPawn && MyPawn->IsLocallyControlled() && GetNetMode() == NM_Client)
{
// if we're a client and we've hit something that is being controlled by the server
if (Impact.GetActor() && Impact.GetActor()->GetRemoteRole() == ROLE_Authority)
{
// notify the server of the hit
ServerNotifyHit(Impact, ShootDir, RandomSeed, ReticleSpread);
}
else if (Impact.GetActor() == NULL)
{
if (Impact.bBlockingHit)
{
// notify the server of the hit
ServerNotifyHit(Impact, ShootDir, RandomSeed, ReticleSpread);
}
else
{
// notify server of the miss
ServerNotifyMiss(ShootDir, RandomSeed, ReticleSpread);
}
}
}
// process a confirmed hit
ProcessInstantHit_Confirmed(Impact, Origin, ShootDir, RandomSeed, ReticleSpread);
}
示例5: DamageTarget
void UCheatManager::DamageTarget(float DamageAmount)
{
APlayerController* const MyPC = GetOuterAPlayerController();
if ((MyPC == NULL) || (MyPC->PlayerCameraManager == NULL))
{
return;
}
check(GetWorld() != NULL);
FVector const CamLoc = MyPC->PlayerCameraManager->GetCameraLocation();
FRotator const CamRot = MyPC->PlayerCameraManager->GetCameraRotation();
FCollisionQueryParams TraceParams(NAME_None, true, MyPC->GetPawn());
FHitResult Hit;
bool bHit = GetWorld()->LineTraceSingle(Hit, CamLoc, CamRot.Vector() * 100000.f + CamLoc, ECC_Pawn, TraceParams);
if (bHit)
{
check(Hit.GetActor() != NULL);
FVector ActorForward, ActorSide, ActorUp;
FRotationMatrix(Hit.GetActor()->GetActorRotation()).GetScaledAxes(ActorForward, ActorSide, ActorUp);
FPointDamageEvent DamageEvent(DamageAmount, Hit, -ActorForward, UDamageType::StaticClass());
Hit.GetActor()->TakeDamage(DamageAmount, DamageEvent, MyPC, MyPC->GetPawn());
}
}
示例6: ProcessInstantHit
void ASWeaponInstant::ProcessInstantHit(const FHitResult& Impact, const FVector& Origin, const FVector& ShootDir)
{
if (MyPawn && MyPawn->IsLocallyControlled() && GetNetMode() == NM_Client)
{
// If we are a client and hit something that is controlled by server
if (Impact.GetActor() && Impact.GetActor()->GetRemoteRole() == ROLE_Authority)
{
// Notify the server of our local hit to validate and apply actual hit damage.
ServerNotifyHit(Impact, ShootDir);
}
else if (Impact.GetActor() == nullptr)
{
if (Impact.bBlockingHit)
{
ServerNotifyHit(Impact, ShootDir);
}
else
{
ServerNotifyMiss(ShootDir);
}
}
}
// Process a confirmed hit.
ProcessInstantHitConfirmed(Impact, Origin, ShootDir);
}
示例7: DestroyTarget
void UCheatManager::DestroyTarget()
{
APlayerController* const MyPC = GetOuterAPlayerController();
if ((MyPC == NULL) || (MyPC->PlayerCameraManager == NULL))
{
return;
}
check(GetWorld() != NULL);
FVector const CamLoc = MyPC->PlayerCameraManager->GetCameraLocation();
FRotator const CamRot = MyPC->PlayerCameraManager->GetCameraRotation();
FCollisionQueryParams TraceParams(NAME_None, true, MyPC->GetPawn());
FHitResult Hit;
bool bHit = GetWorld()->LineTraceSingle(Hit, CamLoc, CamRot.Vector() * 100000.f + CamLoc, ECC_Pawn, TraceParams);
if (bHit)
{
check(Hit.GetActor() != NULL);
APawn* Pawn = Cast<APawn>(Hit.GetActor());
if (Pawn != NULL)
{
if ((Pawn->Controller != NULL) && (Cast<APlayerController>(Pawn->Controller) == NULL))
{
// Destroy any associated controller as long as it's not a player controller.
Pawn->Controller->Destroy();
}
}
Hit.GetActor()->Destroy();
}
}
示例8: Interact
void AKIMCharacter::Interact() {
if (IsInRoationState && PickedUpItem) {
((AKIMInteractionActor*)PickedUpItem)->LayBack(this);
return;
}
FHitResult outHit;
FCollisionQueryParams params;
params.AddIgnoredActor(this);
params.AddIgnoredActor(PickedUpItem);
FVector TraceStart = CameraComponent->GetComponentLocation();
FVector TraceEnd = TraceStart + (CameraComponent->GetForwardVector() * InteractionDistance);
GetWorld()->LineTraceSingleByChannel(outHit, TraceStart, TraceEnd, ECollisionChannel::ECC_PhysicsBody, params);
if (outHit.GetActor() != NULL && outHit.GetActor()->GetClass()->IsChildOf(AKIMInteractionActor::StaticClass())) {
AKIMInteractionActor* InteractionActor = ((AKIMInteractionActor*)outHit.GetActor());
InteractionActor->Interacted(this, outHit.GetComponent());
UE_LOG(LogClass, Warning, TEXT("Interacted with %s"), *outHit.GetActor()->GetName());
UE_LOG(LogClass, Warning, TEXT("(%s)"), *outHit.GetComponent()->GetName());
}
else if (outHit.GetActor() == NULL && PickedUpItem) {
PickedUpItem->DetachRootComponentFromParent(true);
((AKIMInteractionActor*)PickedUpItem)->Droped();
((AKIMInteractionActor*)PickedUpItem)->InteractionType = EKIMInteractionTypes::OnPickUp;
UE_LOG(LogClass, Warning, TEXT("Droped %s"), *PickedUpItem->GetName());
PickedUpItem = NULL;
}
}
示例9: ChooseTargetUnderMouseCursor
void AMainPlayerController::ChooseTargetUnderMouseCursor()
{
/*if (clickedPawn != nullptr) {
delete clickedPawn;
clickedPawn = nullptr;
}*/
// Trace to see what is under the mouse cursor
FHitResult Hit;
GetHitResultUnderCursor(ECC_Pawn, false, Hit);
if (Hit.bBlockingHit) {
//GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Magenta, Hit.GetActor()->GetName());
IGlobalMapInterface * mapObj = Cast<IGlobalMapInterface>(Hit.GetActor());
clickedPawn = Cast<ABasicCharacter>(Hit.GetActor());
if (mapObj != nullptr) {
mapObj->showObjectInformation();
}
/*if (clickedPawn == nullptr) {
Cast<IGlobalMapInterface>(Hit.GetActor())->showObjectInformation();
}*/
}
}
示例10: TraceHitForward
/*Description: Raycasts forward and detects where the player is aiming to adjust the reticles*/
bool APoseidonCharacter::TraceHitForward(APlayerController* InController, FHitResult& OutTraceResult)
{
// Calculate the direction we are 'looking'
FVector CamLoc;
FRotator CamRot;
InController->GetPlayerViewPoint(CamLoc, CamRot);
const FVector TraceDirection = CamRot.Vector();
// Calculate the start location for trace
FVector StartTrace = FVector::ZeroVector;
if (InController)
{
FRotator UnusedRotation;
InController->GetPlayerViewPoint(StartTrace, UnusedRotation);
// Adjust trace so there is nothing blocking the ray between the camera and the pawn, and calculate distance from adjusted start
StartTrace = StartTrace + TraceDirection * ((GetActorLocation() - StartTrace) | TraceDirection);
}
// Calculate endpoint of trace
const FVector EndTrace = StartTrace + TraceDirection * mGrappleRange;
// Setup the trace query
static FName FireTraceIdent = FName(TEXT("GrappleTrace"));
FCollisionQueryParams TraceParams(FireTraceIdent, true, this);
TraceParams.bTraceAsyncScene = true;
// Perform the trace
GetWorld()->LineTraceSingleByChannel(OutTraceResult, StartTrace, EndTrace, COLLISION_GRAPPLE, TraceParams);
if (OutTraceResult.GetActor() != NULL)
{
FString filterEnemy = TEXT("Character");
if (OutTraceResult.GetActor()->GetHumanReadableName().Contains(filterEnemy))
{
if (mIsGrappleReady)
{
PlayerHUD->ChangeCrosshair(EReticleEnum::RE_HIT_AIM);
}
}
else
{
if (mIsGrappleReady)
{
PlayerHUD->ChangeCrosshair(EReticleEnum::RE_AIM);
}
else
{
PlayerHUD->ChangeCrosshair(EReticleEnum::RE_HIP);
}
}
return true;
}
PlayerHUD->ChangeCrosshair(EReticleEnum::RE_HIP);
return false;
}
示例11: ActivateButton
//USE BUTTON CODE//
void APlayerCharacter::ActivateButton()
{
UPeterAnimInstance* PeterAnimInstance = Cast<UPeterAnimInstance>(GetMesh()->GetAnimInstance());
if (PeterAnimInstance)
{
PeterAnimInstance->bIsInteracting = true;
}
if (PhysicsHandleActive)
{
PhysicsHandleActive = false;
}
else if (!PhysicsHandleActive)
{
PhysicsHandleActive = true;
}
bool TraceSuccess;
FHitResult OutHit;
//Uses Trace Channel: PlayerTrace
TraceSuccess = this->TraceFromSelf(OutHit, 300.f, ECollisionChannel::ECC_GameTraceChannel6);
if (TraceSuccess)
{
AInteractable* InteractableObject = NULL;
InteractableObject = Cast<AInteractable>(OutHit.GetActor());
if (Cast<ALiftableBox>(OutHit.GetActor()))
{
if (PhysicsHandleActive)
{
PickedUpBox = Cast<ALiftableBox>(OutHit.GetActor());
if (PickedUpBox->bIsAbove(this) && PickedUpBox->CanBeLifted == true)
{
PhysicsHandler->GrabComponent(OutHit.GetComponent(), OutHit.BoneName, OutHit.Location, true);
}
}
return;
}
else if (InteractableObject && InteractableObject->GetClass()->IsChildOf(ALightSwitch::StaticClass()) == false)
{
if (FVector::Dist(GetActorLocation(), InteractableObject->GetActorLocation()) < 250)
{
InteractableObject->Interact(this);
}
}
}
}
示例12: AttachEffectToTarget_Implementation
void UARFXEffectComponent::AttachEffectToTarget_Implementation(UParticleSystem* FXIn, FHitResult Target, FName AttachSocket, APawn* Causer)
{
if (!Target.GetActor() && !PresitentFX)
return;
AARCharacter* hitTarget = Cast<AARCharacter>(Target.GetActor());
if (!hitTarget)
return;
UParticleSystemComponent* AttachedPSC = UGameplayStatics::SpawnEmitterAttached(PresitentFX, hitTarget->Mesh, AttachSocket);
}
示例13: SimulateInstantHit
void ASWeaponInstant::SimulateInstantHit(const FVector& Origin)
{
const FVector StartTrace = Origin;
const FVector AimDir = GetAdjustedAim();
const FVector EndTrace = StartTrace + (AimDir * WeaponRange);
const FHitResult Impact = WeaponTrace(StartTrace, EndTrace);
if (Impact.bBlockingHit)
{
SpawnImpactEffects(Impact);
SpawnTrailEffects(Impact.ImpactPoint);
}
else
{
SpawnTrailEffects(EndTrace);
}
// Do not spawn near-hit if we actually hit a pawn
if (Impact.GetActor() && Impact.GetActor()->IsA(ASCharacter::StaticClass()))
{
return;
}
for (FConstPawnIterator It = GetWorld()->GetPawnIterator(); It; It++)
{
// Find a locally controlled pawn that is not the instigator of the hit.
ASCharacter* OtherPawn = Cast<ASCharacter>(*It);
if (OtherPawn && OtherPawn != GetPawnOwner() && OtherPawn->IsLocallyControlled())
{
// Calculate shortest distance to point. (using the estimated eye height)
const float DistanceToPawn = FVector::CrossProduct(AimDir, OtherPawn->GetActorLocation() - Origin).Size();
/* Owner can be lost before client gets to simulate the hit. */
ASCharacter* P = GetPawnOwner();
if (P)
{
FVector LookAt = (OtherPawn->GetActorLocation() - GetPawnOwner()->GetActorLocation());
LookAt.Normalize();
float LookDot = FVector::DotProduct(AimDir, LookAt);
if (DistanceToPawn < NearHitMaxDistance && LookDot > 0)
{
// TODO: Play at nearest "almost" hit location.
const FVector SoundLocation = Origin + (AimDir * DistanceToPawn);
// Volume is based on distance to missed shot
float Volume = FMath::Clamp(1 - (DistanceToPawn / NearHitMaxDistance), 0.1f, 1.0f);
UGameplayStatics::PlaySoundAtLocation(this, NearHitSound, /*SoundLocation*/ OtherPawn->GetActorLocation(), Volume);
}
}
}
}
}
示例14: ServerNotifyHit_Implementation
void ASWeaponInstant::ServerNotifyHit_Implementation(const FHitResult Impact, FVector_NetQuantizeNormal ShootDir)
{
// If we have an instigator, calculate the dot between the view and the shot
if (Instigator && (Impact.GetActor() || Impact.bBlockingHit))
{
const FVector Origin = GetMuzzleLocation();
const FVector ViewDir = (Impact.Location - Origin).GetSafeNormal();
const float ViewDotHitDir = FVector::DotProduct(Instigator->GetViewRotation().Vector(), ViewDir);
if (ViewDotHitDir > AllowedViewDotHitDir)
{
// TODO: Check for weapon state
if (Impact.GetActor() == nullptr)
{
if (Impact.bBlockingHit)
{
ProcessInstantHitConfirmed(Impact, Origin, ShootDir);
}
}
// Assume it told the truth about static things because we don't move and the hit
// usually doesn't have significant gameplay implications
else if (Impact.GetActor()->IsRootComponentStatic() || Impact.GetActor()->IsRootComponentStationary())
{
ProcessInstantHitConfirmed(Impact, Origin, ShootDir);
}
else
{
const FBox HitBox = Impact.GetActor()->GetComponentsBoundingBox();
FVector BoxExtent = 0.5 * (HitBox.Max - HitBox.Min);
BoxExtent *= ClientSideHitLeeway;
BoxExtent.X = FMath::Max(20.0f, BoxExtent.X);
BoxExtent.Y = FMath::Max(20.0f, BoxExtent.Y);
BoxExtent.Z = FMath::Max(20.0f, BoxExtent.Z);
const FVector BoxCenter = (HitBox.Min + HitBox.Max) * 0.5;
// If we are within client tolerance
if (FMath::Abs(Impact.Location.Z - BoxCenter.Z) < BoxExtent.Z &&
FMath::Abs(Impact.Location.X - BoxCenter.X) < BoxExtent.X &&
FMath::Abs(Impact.Location.Y - BoxCenter.Y) < BoxExtent.Y)
{
ProcessInstantHitConfirmed(Impact, Origin, ShootDir);
}
}
}
}
// TODO: UE_LOG on failures & rejection
}
示例15: ProcessInstantHit
void AWeapon::ProcessInstantHit(const FHitResult &Impact, const FVector &Origin, const FVector &ShootDir, int32 RandomSeed, float ReticleSpread)
{
const FVector EndTrace = Origin + ShootDir * WeaponConfig.WeaponRange;
const FVector EndPoint = Impact.GetActor() ? Impact.ImpactPoint : EndTrace;
DrawDebugLine(this->GetWorld(), Origin, Impact.TraceEnd, FColor::Black, true, 10000, 10.f);
AEnemy *Enemy = Cast<AEnemy>(Impact.GetActor());
if (Enemy)
{
GEngine->AddOnScreenDebugMessage(-1, 3.f, FColor::Red, "YOU HIT AN ENEMY!!");
Enemy->Destroy();
}
}