当前位置: 首页>>代码示例>>C++>>正文


C++ FHitResult类代码示例

本文整理汇总了C++中FHitResult的典型用法代码示例。如果您正苦于以下问题:C++ FHitResult类的具体用法?C++ FHitResult怎么用?C++ FHitResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FHitResult类的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);
    }
}
开发者ID:t-p-tan,项目名称:CS4350-Die-Another-Day,代码行数:26,代码来源:ShooterWeapon_Instant.cpp

示例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);
		}
	}

}
开发者ID:JackHarb89,项目名称:KIM,代码行数:28,代码来源:KIMCharacter.cpp

示例3: 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;
}
开发者ID:AndreaOsorio,项目名称:PSI,代码行数:61,代码来源:PoseidonCharacter.cpp

示例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);
}
开发者ID:t-p-tan,项目名称:CS4350-Die-Another-Day,代码行数:28,代码来源:ShooterWeapon_Instant.cpp

示例5: GetOuterAPlayerController

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());
	}
}
开发者ID:kidaa,项目名称:UnrealEngineVR,代码行数:25,代码来源:CheatManager.cpp

示例6: GetWorld

const FHitResult UGrabber::GetFirstPhysicsBodyInReach()
{
	/// Get Player position and view data
	FVector PlayerViewPointLocation;
	FRotator PlayerViewPointRotation;
	GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(OUT PlayerViewPointLocation, OUT PlayerViewPointRotation);

	/*UE_LOG(LogTemp, Warning, TEXT("Location: %s, Rotation: %s"), *PlayerViewPointLocation.ToString(), *PlayerViewPointRotation.ToString());*/

	/// Draw Debug Line based on how far can reach
	FVector LineTraceEnd = PlayerViewPointLocation + (PlayerViewPointRotation.Vector() * Reach);
	//DrawDebugLine(GetWorld(), PlayerViewPointLocation, LineTraceEnd, FColor(255, 0, 0), false, 0.f, 0.f, 10.f);

	/// Decide what can detect as collision
	FCollisionQueryParams TraceParameters(FName(TEXT("")), false, GetOwner());

	FHitResult LineTraceHit;
	GetWorld()->LineTraceSingleByObjectType(OUT LineTraceHit, PlayerViewPointLocation, LineTraceEnd, FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody), TraceParameters);

	AActor* ActorHit = LineTraceHit.GetActor();
	if (ActorHit) {
		UE_LOG(LogTemp, Warning, TEXT("Line Trace Hit: %s"), *(ActorHit->GetName()));
	}
	return LineTraceHit;
}
开发者ID:ParhamTaher,项目名称:UnrealSection3,代码行数:25,代码来源:Grabber.cpp

示例7: 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);
}
开发者ID:Raynaron,项目名称:EpicSurvivalGameSeries,代码行数:26,代码来源:SWeaponInstant.cpp

示例8: DrawDebugLine

void UCarditWeapon::Fire()
{
	auto Camera = Cast<ACarditCharacter>(GetOwner())->GetCamera();
	auto CameraLocation = Camera->GetComponentLocation();
	auto EndLocation = Camera->GetComponentLocation() + (Camera->GetComponentRotation().Vector() * MaxRangeInCm);

	DrawDebugLine(GetWorld(), CameraLocation, EndLocation, FColor(255, 0, 0), false, 5.f, 0, 2.5f);

	FHitResult OutHit;

	if (GetWorld()->LineTraceSingleByChannel(
		OutHit,
		CameraLocation,
		EndLocation,
		ECC_Visibility
	)
		)
	{
		if (Cast<ACarditCharacter>(OutHit.GetActor()))
		{
			GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, "Character hit");
			Cast<ACarditGameMode>(UGameplayStatics::GetGameMode(GetWorld()))->DealDamageOntoCharacter(Cast<ACarditCharacter>(OutHit.GetActor()), DamagePerShot);
		}
		else
		{
			UE_LOG(LogTemp, Warning, TEXT("Non-character hit"));
		}
	}
	else
	{
		UE_LOG(LogTemp, Warning, TEXT("Nothing hit"));
	}
}
开发者ID:CarsonHoffman,项目名称:cardit,代码行数:33,代码来源:CarditWeapon.cpp

示例9: WeaponRandomStream

void ABaseWeapon::Instant_Fire()
{
	const int32 RandomSeed = FMath::Rand();
	FRandomStream WeaponRandomStream(RandomSeed);
	const float CurrentSpread = WeaponConfig.WeaponSpread;
	const float SpreadCone = FMath::DegreesToRadians(WeaponConfig.WeaponSpread * 0.5);
	const FVector AimDir = MyPawn->GetActorForwardVector();
	const FVector StartTrace = MyPawn->GetActorLocation();
	const FVector ShootDir = WeaponRandomStream.VRandCone(AimDir, SpreadCone, SpreadCone);
	FVector EndTrace;

	if (Target)
	{
		FVector TargetDir = (MyPawn->GetActorLocation() - Target->GetActorLocation());
		TargetDir.Normalize();
		FVector ShootDir2 = WeaponRandomStream.VRandCone(-TargetDir, SpreadCone, SpreadCone);
		EndTrace = StartTrace + ShootDir2 * WeaponConfig.WeaponRange;
	}
	else
	{
		EndTrace = StartTrace + ShootDir * WeaponConfig.WeaponRange;
	}

	const FHitResult Impact = WeaponTrace(StartTrace, EndTrace);
	SpawnParticle(EndTrace);
	HitActor = Cast<AActor>(Impact.GetActor());

	//DrawDebugLine(GetWorld(), StartTrace, EndTrace, FColor::Red, false, 1.0f);

	if (HitActor)
	{
		Server_DealDamage(Impact, ShootDir, WeaponConfig);
	}
}
开发者ID:ZerosGames,项目名称:FightKillWin,代码行数:34,代码来源:BaseWeapon.cpp

示例10: FHitResult

void ALMPlayerController::RMouseDownSelectTarget()
{
    FHitResult HitRes = FHitResult();
    TArray<TEnumAsByte<EObjectTypeQuery>> ObjectType;
    //只检测一下对象
    ObjectType.Add(EOBJECTTYPEQUERY_SELECTACTOR);

    if (GetHitResultUnderCursorForObjects(ObjectType,false,HitRes))
    {
        if (HitRes.GetComponent() == pCurSelectedComponent)
        {
            return;
        }
        else
        {
            if (pCurSelectedComponent != nullptr)
                pCurSelectedComponent->SetRenderCustomDepth(false);

            pCurSelectedComponent = HitRes.GetComponent();

            pCurSelectedComponent->SetRenderCustomDepth(true);

        }

    }
}
开发者ID:willcong,项目名称:LonelyMen,代码行数:26,代码来源:LMPlayerController.cpp

示例11: 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);
}
开发者ID:Aboutdept,项目名称:ActionRPGGame,代码行数:7,代码来源:ARFXEffectComponent.cpp

示例12: 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();
		}*/
	}
	
}
开发者ID:injir,项目名称:Game,代码行数:25,代码来源:MainPlayerController.cpp

示例13: SmoothInterpolate

// Called every frame
void AMovingPlatform::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	FVector currentPos = movingObject->GetComponentLocation();
	if (pauseTimer > 0.0f)
	{
		pauseTimer -= DeltaTime;
	}
	else
	{
		t = smoothInterpolate->UpdatePosition(currentPos, DeltaTime);
	}

	// update lerp t
	if (t > 1.0f)
	{
		pauseTimer = pauseTime;
		t = 0.0f;
		delete smoothInterpolate;
		if (direction)
		{
			direction = false;
			smoothInterpolate = new SmoothInterpolate(startPos, sloopDist, distToTarget, moveSpeed, sloopPower, sloopMult, 0.0f);
		}
		else
		{
			direction = true;
			smoothInterpolate = new SmoothInterpolate(targetPos->GetComponentLocation(), sloopDist, distToTarget, moveSpeed, sloopPower, sloopMult, 0.0f);
		}
	}

	// calculate movment
	if (direction)
	{
		newPos = MathUtil::Lerp(targetPos->GetComponentLocation(), startPos, t);
	}
	else
	{
		newPos = MathUtil::Lerp(startPos, targetPos->GetComponentLocation(), t);
	}
	time += DeltaTime;
	// move
	FHitResult* moveHitResult = new FHitResult();
	ETeleportType teleType = teleportType ? ETeleportType::TeleportPhysics : ETeleportType::None;
	movingObject->AddWorldOffset(newPos - movingObject->GetComponentLocation(), bSweep, moveHitResult, teleType);
	if (bSweep && !moveHitResult->IsValidBlockingHit())
	{
		movingObject->AddWorldOffset(newPos - movingObject->GetComponentLocation(), false, moveHitResult, teleType);
	}
	else
	{
		smoothInterpolate->SetOldInterpolation();
	}
	//UE_LOG(LogTemp, Warning, TEXT("ReceiveHit - IsValidBlockingHit: %d - time: %d"), moveHitResult->IsValidBlockingHit() , time);

	delete moveHitResult;
}
开发者ID:KitVanDeBunt,项目名称:Proef_Proeve,代码行数:59,代码来源:MovingPlatform.cpp

示例14: if

//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);
			}
		}
	}
}
开发者ID:Snowman5717,项目名称:SymphonyOfShadows,代码行数:56,代码来源:PlayerCharacter.cpp

示例15: GetAdjustedAim

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);
				}
			}
		}
	}
}
开发者ID:Simpl0S,项目名称:EpicSurvivalGameSeries,代码行数:54,代码来源:SWeaponInstant.cpp


注:本文中的FHitResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。